train_test_data_split function is showing problem

Viewed 27

I was trying to make a program to predict the runs made by a cricketer. I used a csv file for data made by me. The code is:

import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
from sklearn.model_selection import train_test_split
#Data
data = pd.read_csv('Rohit Sharma.csv')

X = [['against','wickets','currentrun','weather','ball','over']]

Y = ['runsmade']

x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.33, train_size=None, random_state=42)

reg = LinearRegression()

reg.fit(x_train,y_train)

a = reg.predict(x_test)

print(a)

print(data)

But it showed an error:

ValueError: With n_samples=1, test_size=0.33 and train_size=None, the resulting 
train set will be empty. Adjust any of the aforementioned parameters

How to fix it?

1 Answers

Try this:

Looks like you made an error while selecting the columns of the data. See below.

import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
from sklearn.model_selection import train_test_split
#Data
data = pd.read_csv('Rohit Sharma.csv')

X = data[['against','wickets','currentrun','weather','ball','over']].to_numpy()

Y = data['runsmade'].to_numpy()

x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.33,  random_state=42)

reg = LinearRegression()

reg.fit(x_train,y_train)

a = reg.predict(x_test)

print(a)

print(data)
Related