(Apr-21-2020, 06:40 PM)DT2000 Wrote: I am curious why you have line 8, the import of the definition commented out? This will throw the error if it is not defined.
import math import csv import random import numpy as np import pandas as pd import sklearn from sklearn.ensemble import RandomForestClassifier #from sklearn import cross_validation, linear_model from sklearn.model_selection import cross_validate from sklearn import linear_model from sklearn.model_selection import cross_val_score from sklearn.model_selection import train_test_split
The reason is that it throws up this specific error:
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-2-f28d8d77736c> in <module> 6 import sklearn 7 from sklearn.ensemble import RandomForestClassifier ----> 8 from sklearn import cross_validation, linear_model 9 from sklearn.model_selection import cross_validate 10 from sklearn import linear_model ImportError: cannot import name 'cross_validation' from 'sklearn' (/anaconda3/lib/python3.7/site-packages/sklearn/__init__.py)
Sometimes, the best way to get answers to questions is by asking yourself or rather asking others that may not have the answer.
Here's the solution:
I simply modified the following line:
from:
print(cross_validation.cross_val_score(model, np.array(X), np.array(y), cv=10, scoring='accuracy').mean())TO:
print(sklearn.model_selection.cross_val_score(model, np.array(X), np.array(y), cv=10, scoring='accuracy').mean())Specifically, the object cross_validation is deprecated or obsolete(I think) and sklearn.model_selection works now like charm.
Thanks to you all.