Fish_species
Importpandasaspd
Importrandom
Fromsklearn.linear_modelimportLinearRegression
#createthedataset
Fish_species=[‘Tuna’,‘Salmon’,‘Trout’,‘Bass’,‘Sardine’,‘Cod’,‘Mackerel’]
Weights=[]
Foriinrange(50):
Fish_weight=[]
Forjinrange(7):
Weight=random.randint(1,20)
Fish_weight.append(weight)
Weights.append(fish_weight)
Df=pd.DataFrame(weights,columns=fish_species)
#createthelinearregressionmodel
X=df.iloc[:,:-1]#independentvariables
Y=df.iloc[:,-1]#targetvariable
Model=LinearRegression()
Model.fit(X,y)
#predicttheweightofanewfishspecies
New_fish=[[10,12,15,7,4,8]]#exampleinput
Predicted_weight=model.predict(new_fish)
Print(“Predictedweight:”,predicted_weight