image_output_1.png
from sklearn.linear_model import LinearRegression

from sklearn.metrics import r2_score

from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt

import pandas as pd

item_categories = pd.read_csv('/kaggle/input/competitive-data-science-predict-future-sales/item_categories.csv')
items = pd.read_csv('/kaggle/input/competitive-data-science-predict-future-sales/items.csv')
sales_train = pd.read_csv('/kaggle/input/competitive-data-science-predict-future-sales/sales_train.csv', parse_dates=['date'])
sample_submission = pd.read_csv('/kaggle/input/competitive-data-science-predict-future-sales/sample_submission.csv')
shops = pd.read_csv('/kaggle/input/competitive-data-science-predict-future-sales/shops.csv')
data_test = pd.read_csv('/kaggle/input/competitive-data-science-predict-future-sales/test.csv')

sales_train = sales_train[sales_train.item_price < 40000]
sales_train = sales_train[sales_train.item_cnt_day < 200]
sales_train = sales_train[sales_train.item_cnt_day > -1]
columns = ['date', 'date_block_num', 'shop_id', 'item_id', 'item_price', 'item_cnt_day']
sales_train.drop_duplicates(columns, keep='first', inplace=True)

data = sales_train[['item_cnt_day', 'item_price']]

x = data.iloc[:, :-1].values
y = data.iloc[:, 1].values
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=1 / 3, random_state=123, shuffle=1)
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

r2_score(y_test, y_pred)