How to Predict Values When a Data Set Is Scaled in Python


In this example we will show how to predict values when a data set is scaled in Python.

Source Code

import pandas as pd
from sklearn import linear_model
from sklearn.preprocessing import StandardScaler

df = pd.read_csv("advertising.csv")

X = df[["TV", "radio", "newspaper"]]
y = df["sales"]

scaler = StandardScaler()
scaled_X = scaler.fit_transform(X)

reg = linear_model.LinearRegression().fit(scaled_X, y)

scaled = scaler.transform([[50, 30, 20]])

predict_sales = reg.predict([scaled[0]])

print(predict_sales)

Output:

[10.86227229]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments