Need help; iris-train - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Need help; iris-train (/thread-17450.html) |
Need help; iris-train - Karin - Apr-11-2019 I'm a beginner of machine learning and now learning scikit-learn using iris analysis. My code is here... import pandas as pd from sklearn import svm, metrics from sklearn.model_selection import train_test_split csv = pd.read_csv('iris.csv') csv_data = csv[["SepalLength", "SepalWidth", "PetalLength", "PetalWidth"]] csv_label = csv["Name"] train_data, test_data, train_label, test_label = train_test_split(csv_data, csv_label) clf = svm.SVC(gamma = 'auto') clf.fit(train_data, train_label) pre = clf.predict(test_data)But at the end it said anyone can solve it??
RE: Need help; iris-train - scidam - Apr-11-2019 To solve this, we need to know content of the file "iris.csv". It seems that it hasn't been properly loaded or has column names differ from those you are used in line #7. It would be better, if you passed numpy arrays to scikit-learn classifiers (not data frames), e.g. X = csv[[...column names go here...]].values # gets numpy array y = csv["grouping variable name goes here"].values # gets numpy array # you need to encode grouping variable y, e.g. using LabelEncoder from scikit-learn. # you probably need to do column-wise scaling of your data, # e.g. using StandardScaler or Pandas facilities. # do splitting, training and testing with X, y and scikit-learn RE: Need help; iris-train - Karin - Apr-12-2019 To solve this, we need to know content of the file "iris.csv". It seems that it hasn't been properly loaded or has column names differ from those you are used in line #7. Thanks!! I didn't realize the difference of the name. Now I got it. Sorry, it was too easy question...but great thanks! |