When creating a post, please add:
- Week 1
- Neural network implementation in python
- error in my code while running it is the broadcasting error while using matmul
shirt_data = np.array([
["Shirt_ID", "Brand", "Material", "Price", "Durability_Rating", "Style", "Comfort_Rating",
"Sales_Last_Year", "Return_Rate", "Production_Cost", "Environmental_Impact", "Customer_Feedback",
"Reliability_Score", "Popularity", "Market_Trend"],
[1, "Zara", "Cotton", 25, 8, "Casual", 9, 15000, "3%", 12, "Medium", 4.5, 8.5, "High", "Increasing"],
[2, "H&M", "Polyester", 20, 6, "Formal", 7, 12000, "5%", 8, "High", 4.0, 6.7, "Medium", "Stable"],
[3, "Nike", "Dri-Fit", 30, 9, "Sports", 8, 18000, "2%", 15, "Low", 4.7, 8.9, "High", "Increasing"],
[4, "Uniqlo", "Linen", 35, 7, "Casual", 8, 14000, "4%", 18, "Medium", 4.3, 7.5, "Medium", "Stable"],
[5, "Levi’s", "Cotton", 40, 9, "Formal", 9, 16000, "3%", 20, "Low", 4.8, 8.9, "High", "Increasing"]
])
shirt_data
import pandas as pd
df = pd.DataFrame(shirt_data)
df
df1 = df.copy()
x_train = df1.iloc[1:,[3,4,6,9]].to_numpy()
x_train = x_train.astype(float)
print(x_train)
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y_train = df1.iloc[:,-1]
y_train = le.fit_transform(y_train)
y_train
print(y_train.shape[0])
print(x_train , "\n\n\n")
print(y_train ,"\n\n\n")
def sigmoid(x):
return 1/(1+np.exp(-x))
def my_dense(a,w,b):
a = np.matmul(a,w)
b = np.broadcast_to(b , a.shape)
# b = b.reshape(b.shape[0],1)
a = a+ b
print(a)
a = sigmoid(a)
return a
def my_sequential(x,w1,b1,w2,b2):
a1 = my_dense(x,w1,b1)
a2 = my_dense(a1,w2,b2)
return a2
w1 = np.random.rand(4,3)
print(w1,"\n\n\n\n")
b1 = np.random.rand(1,5)
print(b1,"\n\n\n\n")
w2 = np.random.rand(3,1)
print(w2,"\n\n\n\n")
b2 = np.random.rand(1,3)
print(b2,"\n\n\n\n")
y_pred = my_sequential(x_train,w1,b1,w2,b2)
y_pred