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?
- Load the datasets individually.
- Make sure they are in the same format of rows and columns (features).
- Use the
- Use the
predictthe output after training.
# Load the data train = pd.read_csv('train.csv') test = pd.read_csv('test.csv') # Split features and value # when trying to predict column "target" X_train, y_train = train.drop("target"), train["target"] X_test, y_test = test.drop("target"), test["target"] # 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)
Answered By – skillsmuggler
Answer Checked By – Pedro (AngularFixing Volunteer)