0% found this document useful (0 votes)
17 views

Laptop

Uploaded by

snigenigmatic972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Laptop

Uploaded by

snigenigmatic972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

import numpy as np

import matplotlib.pyplot as plt


import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR

df = pd.read_csv('E:\\PAML\\Week_2\\laptop_price.csv',
encoding='latin1')
df

laptop_ID Company Product \


0 1 Apple MacBook Pro
1 2 Apple Macbook Air
2 3 HP 250 G6
3 4 Apple MacBook Pro
4 5 Apple MacBook Pro
... ... ... ...
1298 1316 Lenovo Yoga 500-14ISK
1299 1317 Lenovo Yoga 900-13ISK
1300 1318 Lenovo IdeaPad 100S-14IBR
1301 1319 HP 15-AC110nv (i7-6500U/6GB/1TB/Radeon
1302 1320 Asus X553SA-XX031T (N3050/4GB/500GB/W10)

TypeName Inches
ScreenResolution \
0 Ultrabook 13.3 IPS Panel Retina Display
2560x1600
1 Ultrabook 13.3
1440x900
2 Notebook 15.6 Full HD
1920x1080
3 Ultrabook 15.4 IPS Panel Retina Display
2880x1800
4 Ultrabook 13.3 IPS Panel Retina Display
2560x1600
... ... ...
...
1298 2 in 1 Convertible 14.0 IPS Panel Full HD / Touchscreen
1920x1080
1299 2 in 1 Convertible 13.3 IPS Panel Quad HD+ / Touchscreen
3200x1800
1300 Notebook 14.0
1366x768
1301 Notebook 15.6
1366x768
1302 Notebook 15.6
1366x768
Cpu Ram Memory
\
0 Intel Core i5 2.3GHz 8GB 128GB SSD

1 Intel Core i5 1.8GHz 8GB 128GB Flash Storage

2 Intel Core i5 7200U 2.5GHz 8GB 256GB SSD

3 Intel Core i7 2.7GHz 16GB 512GB SSD

4 Intel Core i5 3.1GHz 8GB 256GB SSD

... ... ... ...

1298 Intel Core i7 6500U 2.5GHz 4GB 128GB SSD

1299 Intel Core i7 6500U 2.5GHz 16GB 512GB SSD

1300 Intel Celeron Dual Core N3050 1.6GHz 2GB 64GB Flash Storage

1301 Intel Core i7 6500U 2.5GHz 6GB 1TB HDD

1302 Intel Celeron Dual Core N3050 1.6GHz 4GB 500GB HDD

Gpu OpSys Weight Price_euros


0 Intel Iris Plus Graphics 640 macOS 1.37kg 1339.69
1 Intel HD Graphics 6000 macOS 1.34kg 898.94
2 Intel HD Graphics 620 No OS 1.86kg 575.00
3 AMD Radeon Pro 455 macOS 1.83kg 2537.45
4 Intel Iris Plus Graphics 650 macOS 1.37kg 1803.60
... ... ... ... ...
1298 Intel HD Graphics 520 Windows 10 1.8kg 638.00
1299 Intel HD Graphics 520 Windows 10 1.3kg 1499.00
1300 Intel HD Graphics Windows 10 1.5kg 229.00
1301 AMD Radeon R5 M330 Windows 10 2.19kg 764.00
1302 Intel HD Graphics Windows 10 2.2kg 369.00

[1303 rows x 13 columns]

dataset = df.copy()

dataset.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1303 entries, 0 to 1302
Data columns (total 13 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 laptop_ID 1303 non-null int64
1 Company 1303 non-null object
2 Product 1303 non-null object
3 TypeName 1303 non-null object
4 Inches 1303 non-null float64
5 ScreenResolution 1303 non-null object
6 Cpu 1303 non-null object
7 Ram 1303 non-null object
8 Memory 1303 non-null object
9 Gpu 1303 non-null object
10 OpSys 1303 non-null object
11 Weight 1303 non-null object
12 Price_euros 1303 non-null float64
dtypes: float64(2), int64(1), object(10)
memory usage: 132.5+ KB

dataset.dropna(axis=0, inplace=True)
dataset.dropna(axis=1, inplace=True)

dataset.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1303 entries, 0 to 1302
Data columns (total 13 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 laptop_ID 1303 non-null int64
1 Company 1303 non-null object
2 Product 1303 non-null object
3 TypeName 1303 non-null object
4 Inches 1303 non-null float64
5 ScreenResolution 1303 non-null object
6 Cpu 1303 non-null object
7 Ram 1303 non-null object
8 Memory 1303 non-null object
9 Gpu 1303 non-null object
10 OpSys 1303 non-null object
11 Weight 1303 non-null object
12 Price_euros 1303 non-null float64
dtypes: float64(2), int64(1), object(10)
memory usage: 132.5+ KB

X =
df.drop(['Memory','Cpu','Gpu','ScreenResolution','laptop_ID','Price_eu
ros','Company','Product','TypeName','OpSys'], axis=1)
X['Ram']=X['Ram'].str.replace('GB','').astype(float)
X['Weight']=X['Weight'].str.replace('kg','').astype(float)
y = df['Price_euros']

X_train, X_test, y_train, y_test = train_test_split(X,y,


test_size=0.2, random_state=42)
linear = LinearRegression()
linear.fit(X_train, y_train)
y_pred_data=linear.predict(X_test)
linear.score(X_test, y_test)

0.5561474558430259

svr = SVR(kernel='linear')
svr.fit(X_train, y_train)
y_pred_data1=svr.predict(X_test)
svr.score(X_test, y_test)

0.5568239882131703

actual = y_test.to_numpy()
actual = actual.reshape(-1,1)
y_pred_data = y_pred_data.reshape(-1,1)
plt.plot(actual, color = 'red', label = 'Real data')
plt.plot(y_pred_data, color = 'blue', label = 'Predicted data')
plt.title('Real vs Predicted data')
plt.legend()
plt.show()
# Analyze the impact on accuracy. Use
# hyperparameter tuning to optimize an
# SVR model for laptop prices. Explain how this
# affects overfitting.

You might also like