ML_Lab_01999676272
ML_Lab_01999676272
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.25,
random_state = 0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
Explanation:
1. Importing Libraries:
(a) The code begins by importing necessary libraries:
- `import numpy as nm` for numerical operations.
- `import matplotlib.pyplot as mtp` for creating plots.
- `import pandas as pd` for data manipulation.
4. Feature Scaling:
(a) Feature scaling is applied to the dataset:
- `StandardScaler` standardizes features by removing the mean and scaling to unit
variance.
- The scaler `sc` is fitted to the training data and transforms both the training and
test data.
# importing libraries
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
#importing datasets
data_set= pd.read_csv('user_data.csv')
#feature Scaling
from sklearn.preprocessing import StandardScaler
st_x= StandardScaler()
x_train= st_x.fit_transform(x_train)
x_test= st_x.transform(x_test)
Explanation:
1. Importing Libraries:
(a) The code begins by importing necessary libraries:
- `import numpy as nm` for numerical operations.
- `import matplotlib.pyplot as mtp` for creating plots.
- `import pandas as pd` for data manipulation.
2. Importing the Dataset:
(a) The dataset is read from a CSV file and loaded into a pandas DataFrame named
`data_set`.
(b) Extracting independent and dependent variables:
- `x` contains the values of the 3rd and 4th columns (indices 2 and 3) from the
dataset.
- `y` contains the values of the 5th column (index 4) from the dataset.
4. Feature Scaling:
(a) Feature scaling is applied to the dataset:
- `StandardScaler` standardizes features by removing the mean and scaling to unit
variance.
- The scaler `st_x` is fitted to the training data and transforms both the training and
test data.
# Importing libraries
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
# Importing datasets
data_set= pd.read_csv('user_data.csv')
1. Importing Libraries:
(a) The code begins by importing necessary libraries:
- `import numpy as nm` for numerical operations.
- `import matplotlib.pyplot as mtp` for creating plots.
- `import pandas as pd` for data manipulation.
5. Feature Scaling:
(a) Feature scaling is applied to the dataset:
- `StandardScaler` standardizes features by removing the mean and scaling to unit
variance.
- The scaler `st_x` is fitted to the training data and transforms both the training and
test data.
# Importing libraries
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
# Importing datasets
data_set= pd.read_csv('user_data.csv')
# Feature Scaling
from sklearn.preprocessing import StandardScaler
st_x= StandardScaler()
x_train= st_x.fit_transform(x_train)
x_test= st_x.transform(x_test)
1. Importing Libraries:
(a) The code begins by importing necessary libraries:
- `import numpy as nm` for numerical operations.
- `import matplotlib.pyplot as mtp` for creating plots.
- `import pandas as pd` for data manipulation.
5. Feature Scaling:
(a) Feature scaling is applied to the dataset:
- `StandardScaler` standardizes features by removing the mean and scaling to unit
variance.
- The scaler `st_x` is fitted to the training data and transforms both the training and
test data.