0
votes
#Collecting Data from these columns
X = dataframe['Primary Type'].value_counts().loc['THEFT']
y = dataframe['Year'].value_counts()

#Dividing Data into Test and Train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

#Trainng the Algorithm
regressor = LinearRegression()
regressor.fit(X_train, y_train)

#Making the Predictions
y_pred = regressor.predict(X_test)

#In the form of table
df= pd.DataFrame({'Actual': y_test, 'Predict': y_pred})
print (df)

I am getting an type error while training a model. I am not getting this how can I overcome on this problem. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) on this statement I am getting problem. Please help me out.

1
Please show us the full traceback of your error so that we can identify where the error occurs.Joel

1 Answers

0
votes

I am guessing the issue is with the input type you are giving. values_count returns result of type series. test_train_split takes the following inputs.

Allowed inputs are lists, numpy arrays, scipy-sparse matrices or pandas dataframes.

To use value count results as input to test_train_split convert in into list as follows.

dataframe[column].value_counts().index.tolist() 

If you atleast add partial data frame if they are too big to add full, I can help further.