-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise.py
More file actions
27 lines (20 loc) · 834 Bytes
/
Copy pathexercise.py
File metadata and controls
27 lines (20 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
# Load the dataset
data = pd.read_csv("winequality-red.csv", delimiter=";")
# Split the data into features and target variable
X = data.drop('quality', axis=1)
y = data['quality']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create a StandardScaler object
scaler = StandardScaler()
# Fit the scaler on the training data
scaler.fit(X_train)
# Transform the training and testing data
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Print the scaled data (first 5 rows)
print("Scaled Training Data:\n", X_train_scaled[:5])
print("\nScaled Testing Data:\n", X_test_scaled[:5])