So I was trying to follow along a course with Jupyter Notebook (which was made in 2020) and I ran into a couple of errors. Most were some I could easily solved because they were simply deprecated/removed commands that I could easily replace. But with these two errors, I have no idea what the real issue is, and seeing past people's questions and answers has not helped me, so I'm bringing it here.
First error
Description: I have saved a music recommender model using joblib and I am trying to call the saved model to make a prediction based on age (21) and gender (1, which represents male)
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
import joblib
Code I commented out
#musicdata = pd.read_csv('musicgenres.csv')
#X = musicdata.drop(columns=['Genre'])
#y = musicdata['Genre']
#model = DecisionTreeClassifier()
#model.fit(X, y)
model = joblib.dump(model, 'music-recommender.joblib')
predictions = model.predict([[21, 1]])
predictions
Error message:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10056/639016337.py in
14
15 model = joblib.dump(model, ‘music-recommender.joblib’)
—> 16 predictions = model.predict(21)
17 predictions
AttributeError: ‘list’ object has no attribute ‘predict’
Second error
Description: The course didn't explain to me the purpose of any of this code on purpose yet, but it should output a visual representation of decision trees.
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
musicdata = pd.read_csv('musicgenres.csv')
X = musicdata.drop(columns=['Genre'])
y = musicdata['Genre']
model = DecisionTreeClassifier()
model.fit(X, y)
tree.export_graphviz(model, out_file='music-recommender.dot',
feature_names= ['age', 'gender'],
class_name=sorted(y.unique()),
label='all',
rounded=True,
filled=True)
Error message:
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10056/3981914369.py in
13 model.fit(X, y)
14
—> 15 tree.export_graphviz(model, out_file=‘music-recommender.dot’,
16 feature_names= [‘age’, ‘gender’],
17 class_name=sorted(y.unique()),
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
—> 63 return f(*args, **kwargs)
64
65 # extra_args > 0
TypeError: export_graphviz() got an unexpected keyword argument ‘class_name’
If anybody knows what I'm doing wrong or what I should write in my cell instead, please tell me.