Issue
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
Dt = pd.read_csv("D:\wisc_bc_data.csv")
'''
print(Dt.shape)
print(Dt.head())
'''
def changer(x):
if x == 'B':
return 0
else:
return 1
Dt['diagnosis'] = Dt['diagnosis'].map(lambda x: changer(x))
features = Dt[2:12]
Diagnosis = Dt['diagnosis']
train_features, test_features, train_labels, test_labels = train_test_split(features, Diagnosis) 'this line emits error code'
'''
this is my code and i used dataset from here: https://gomguard.tistory.com/52
'''
I'd like to split data for logistic regression. However, There was an error code like this:
ValueError Traceback (most recent call last) in ----> 1 train_features, test_features, train_labels, test_labels = train_test_split(features, Diagnosis)
D:\python\lib\site-packages\sklearn\model_selection_split.py in train_test_split(*arrays, **options) 2116 raise TypeError("Invalid parameters passed: %s" % str(options)) 2117 -> 2118 arrays = indexable(*arrays) 2119 2120 n_samples = _num_samples(arrays[0])
D:\python\lib\site-packages\sklearn\utils\validation.py in indexable(*iterables) 246 """ 247 result = [_make_indexable(X) for X in iterables] --> 248 check_consistent_length(*result) 249 return result 250
D:\python\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays) 210 if len(uniques) > 1: 211 raise ValueError("Found input variables with inconsistent numbers of" --> 212 " samples: %r" % [int(l) for l in lengths]) 213 214
ValueError: Found input variables with inconsistent numbers of samples: [10, 569] how can I fix it?
Solution
I think features = Dt[2:12]
results in your error.
Your attempt is to slice features, but the python interprets the code to slice records.
So, change the code as Dt.iloc[:, 2:12
].
Answered By - Gilseung Ahn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.