Skip to content

Instantly share code, notes, and snippets.

@grohith327
Created June 13, 2018 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grohith327/fe5251580026c43f0c6f088e342544f5 to your computer and use it in GitHub Desktop.
Save grohith327/fe5251580026c43f0c6f088e342544f5 to your computer and use it in GitHub Desktop.
import numpy as np
from sklearn.cross_validation import train_test_split
## Retrieve features
X = df.values.tolist()
Y = []
## Convert classes in Strings to Integers
for val in target:
if(val == 'Iris-setosa'):
Y.append(0)
elif(val == 'Iris-virginica'):
Y.append(2)
else:
Y.append(1)
## Make them as numpy array
X = np.array(X)
Y = np.array(Y)
## Shuffle and split the data into training and test set
x_train, x_test, y_train, y_test = train_test_split(X,Y,train_size=0.9)
## Make them as numpy arrays
x_train = np.array(x_train)
y_train = np.array(y_train)
x_test = np.array(x_test)
y_test = np.array(y_test)
@kanuptiwari
Copy link

when i tried to run this file along with the other 3 files there is some error in cross_validation. Do we have to use some different version of scikit learn lib or what?
Only this part is troubling me

@grohith327
Copy link
Author

grohith327 commented Apr 1, 2020

This gist uses an old version of sklearn. The train_test_split module has been to moved to model_selection. Use the following import command instead of one on line 2. from sklearn.model_selection import train_test_split

when i tried to run this file along with the other 3 files there is some error in cross_validation. Do we have to use some different version of scikit learn lib or what?
Only this part is troubling me

@kanuptiwari
Copy link

I don't know if can help me further or not but only up to scatter plot is resulting as an output. I changed it to model.selection but still

@grohith327
Copy link
Author

Please post the error you are facing

@kanuptiwari
Copy link

after the scatter plot the whole window disappears and the code exits with 1

@kanuptiwari
Copy link

Screenshot (110)
Screenshot (111)
Screenshot (110)
Screenshot (111)

@grohith327
Copy link
Author

The code did run successfully. The accuracy is printed in the output.

@kanuptiwari
Copy link

Okay I thought the graph that you showed in the article should also be printed.??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment