0
$\begingroup$

I'm looking to create a Random Forest Classifier to predict NBA standings x years in advance. The goal is to show the chances of a team being one of the five worst teams, the 6-10th worst team, 11-15th worst team, etc. Most of the columns shown below are descriptive statistics showing number of players drafted by that team, number signed in FA, win percentage in current/previous years, number of award nominations players on that team have received, draft capital the team has had in previous years, salary cap statistics, etc

I am new to machine learning and am having trouble building with my model. The accuracy score I am getting is low and the probabilities for my testing data (not shown here) are poor.

Any recommendations on steps to improve this or recommended resources?

df = pd.read_csv('Team Profile v8.csv',header=0)

df = df.drop(['winPercRank','winPerc1YearFuture','winPerc1YearFutureRank',
              'winPerc2YearFuture','winPerc2YearFutureRank',
              'winPerc3YearFuture','winPerc3YearFutureRank','season'],axis=1)

df = df.dropna()

y = df.iloc[:, 4].values
X = df.drop('winPercClass1YearFuture',axis=1)
print(X.info())
X = pd.get_dummies(X)

X = X.iloc[:].values

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

clf = RandomForestClassifier(n_estimators=100)

clf.fit(X_train, y_train)
clf.score(X_test,y_test)
print(X.info())

<class 'pandas.core.frame.DataFrame'>
Int64Index: 270 entries, 0 to 269
Data columns (total 44 columns):
 #   Column                Non-Null Count  Dtype  
---  ------                --------------  -----  
 0   team                  270 non-null    object 
 1   draft                 270 non-null    int64  
 2   trade                 270 non-null    int64  
 3   fa                    270 non-null    int64  
 4   winPerc               270 non-null    float64
 5   winPercPrev           270 non-null    float64
 6   prevLottery           270 non-null    int64  
 7   prevFirstRound        270 non-null    int64  
 8   prevSecondRound       270 non-null    int64  
 9   prevConferenceFinals  270 non-null    int64  
 10  prevNBAFinalsLoss     270 non-null    int64  
 11  prevNBAChampion       270 non-null    int64  
 12  winPercPrevRank       270 non-null    int64  
 13  winPerc2Prev          270 non-null    float64
 14  winPerc2PrevRank      270 non-null    int64  
 15  winPerc3Prev          270 non-null    float64
 16  winPerc3PrevRank      270 non-null    int64  
 17  mvpTot                270 non-null    int64  
 18  allNBA1               270 non-null    int64  
 19  allNBA2               270 non-null    int64  
 20  allNBA3               270 non-null    int64  
 21  allNBATot             270 non-null    int64  
 22  allDefense1           270 non-null    int64  
 23  allDefense2           270 non-null    int64  
 24  allDefenseTot         270 non-null    int64  
 25  allStarTot            270 non-null    int64  
 26  round1                270 non-null    int64  
 27  round2                270 non-null    int64  
 28  undrafted             270 non-null    int64  
 29  avgAge                270 non-null    float64
 30  populationDummy       270 non-null    float64
 31  draftCapital          270 non-null    float64
 32  draftCapitalPrev      270 non-null    float64
 33  draftCapital2Prev     270 non-null    float64
 34  draftCapital3Prev     270 non-null    float64
 35  activeCap             270 non-null    int64  
 36  activeCapTop3         270 non-null    int64  
 37  salaryPercTop3        270 non-null    float64
 38  p1YearsLeft           270 non-null    int64  
 39  p2YearsLeft           270 non-null    int64  
 40  p3YearsLeft           270 non-null    int64  
 41  deadCap               270 non-null    int64  
 42  totalCap              270 non-null    int64  
 43  capSpace              270 non-null    int64  
dtypes: float64(11), int64(32), object(1)
memory usage: 94.9+ KB
None
print("ACCURACY OF THE MODEL: ",clf.score(X_test,y_test))

ACCURACY OF THE MODEL:  0.27941176470588236
$\endgroup$
0

1 Answer 1

0
$\begingroup$

Having too many variables can be a huge issue : if you have variables with less direct impact, they'll impact your Random Forest and make it less efficient. You have to find the right balance. Just so you understand, you should try applying your model with only the 5, 10 and 20 "best features" according to you (arbitrary) and see how accuracy evolves. Then if there's a real change, you can apply more precise feature selection algorithms.

Another thing : One good way to do it is train your algorithm to one season (2019-2020 for example) and test it to another (2020-2021), so your classes (ranked 1-5, 6-10, 11-15, ...) are represented the same as the reality. Here you seem to randomly cut your dataset, which can cause issues when you only have 270 entries.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.