GR P Assignment Code
GR P Assignment Code
df = pd.read_csv('/content/drive/MyDrive/Assignment/laptop_price.csv',
encoding='latin1')
print(df.head())
print(df.dtypes)
# Statistical summary
summary = df.describe()
print(summary)
# Now you can handle missing values using methods like imputation or dropping
missing_values = df.isnull().sum()
print(missing_values)
dependent_variable = 'Price_euros'
df['Weight'] = df['Weight'].astype(str)
correlation = df[numerical_columns].corr()
print(correlation['Price_euros'])
y = df['Price_euros']
model = LinearRegression()
model.fit(X_train, y_train)
# Make predictions
predictions = model.predict(X_test)
The model created above is a supervised learning model. This is because it is trained on
labeled data where the algorithm learns from the input-output pairs. In supervised
learning, the model aims to learn the mapping function from the input variables to the
output variable.
df['ScreenResolution_Width'] = df['ScreenResolution'].str.extract(r'(\d+)x\d+')
df['ScreenResolution_Height'] = df['ScreenResolution'].str.extract(r'\d+x(\d+)')
df['ScreenResolution_Width'] = pd.to_numeric(df['ScreenResolution_Width'],
errors='coerce')
df['ScreenResolution_Height'] = pd.to_numeric(df['ScreenResolution_Height'],
errors='coerce')
df.dropna(subset=['ScreenResolution_Width', 'ScreenResolution_Height'],
inplace=True)
# Create and train the Linear Regression model with new variables
model_new = LinearRegression()
model_new.fit(X_train_new, y_train)
# Make predictions with new variables
predictions_new = model_new.predict(X_test_new)