by using this code, can you extend and accomplish the tasks listed. Code: import pandas…
- User
by using this code, can you extend and accomplish the tasks listed. Code: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler
Load the dataset
csv_file_path = "garments_worker_productivity.csv" df = pd.read_csv(csv_file_path)
Inspect the distribution
print(df["actual_productivity"].describe())
Transform actual_productivity
Transform ‘actual_productivity’ to a binary variable
threshold = 0.5 df["productivity_class"] = (df["actual_productivity"] >= threshold).astype(int)
Check the transformation
print(df["productivity_class"].value_counts())
Visualize the distribution of classes
sns.countplot(x="productivity_class", data=df) plt.title("Distribution of Productivity Classes") plt.show()
Normalize Features (Excluding the Target Variable)
Define features and target
X = df.drop(["actual_productivity", "productivity_class"], axis=1) y = df["productivity_class"]
Convert categorical variables into dummies
X = pd.get_dummies(X)
Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Normalize - Fit StandardScaler on X_train and transform both X_train and X_test
scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test)
If needed, visualize the normalized training data (optional)
print(pd.DataFrame(X_train_scaled, columns=X_train.columns).head())
Confirm the splitting
print(f"Training Set Size: {len(X_train)}") print(f"Test Set Size: {len(X_test)}")
tasks: B. Developing ANN from Scratch 2.2 Construct a 3-layers feedforward network with X input neurons, 20 hidden neurons, and Y output neurons. You must identify the values of X and Y yourself (Hint: Lecture # 3 ANN architecture design). Identify an appropriate activation function and justify your choice. 2.3 Write a computer program using a high-level programming language of your choice (Python with NumPy or C/C++ or Java) to train and test the neural network using the Backpropagation algorithm from scratch WITHOUT using any machine learning library. C. Performance Evaluation 2.4 Evaluate the NN using state-of-the-art evaluation metrics. D. Performance Comparison 2.5 Train a new neural network classifier with 10 hidden neurons and evaluate its performance. Repeat the process for training and testing neural network classifier with 30 hidden neurons. 2.6 Contrast the differences and compare among the performance of three trained neural network classifiers (i.e., with 20, 10 and 30 hidden neurons). Justify your observations.
- Assistant
- User
does this accomplish the tasks
- Assistant
- User
can you implement the changes to the code
- Assistant