0 votes
1 view
in Data Science by (11.2k points)

I have gone through multiple questions that help divide your dataframe into train and test, with scikit, without etc.

But my question is I have 2 different csvs ( 2 different dataframes from different years). I want to use one as train and other as test?

How to do so for LinearRegression / any model?

1 Answer

0 votes
by (16.1k points)

Follow the below steps to accomplish your task:

1.Load the datasets individually.

2. They should be in the same format of rows and columns .

3.Use the train set to fit the model.

4.Use the test set to predict the output after training.

# Load the data

train = pd.read_csv('train.csv')

test = pd.read_csv('test.csv')

# Fit (train) model

reg = LinearRegression()

reg.fit(X_train, y_train)

# Predict

pred = reg.predict(X_test)

# Score

accuracy = reg.socre(X_test, y_test)