خطوات إنشاء شبكة عصبية بسيطة بإستخدام Keras.
import numpy as np
from sklearn.datasets import load_iris
iris =load_iris()
print(iris.DESCR)
X = iris.data
y = iris.target
from keras.utils import to_categorical
y = to_categorical(y)
from sklearn.model_selection import train_test_split
X_train, X_test ,y_train,y_test =train_test_split(X,y,test=0.33,random_state=42)
from sklearn.preprocessing import MinMaxScaler
scaler_object =MinMAxScaler()
scaler_object.fit(X_train)
scaled_X_train = scaler_object.transform(X_train)
scaled_X_test = scaler_object.transform(X_test)
from Keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(8,input_dim=4,activation='relu'))
model.add(Dense(8,input_dim=4,activation='relu'))
model.add(Dense(3,activation='softmax'))
model.compile(loss='categorical_crossentropy,optmizer='adam',metrics=['accuracy'])
model.summary
model.fit(scaled_X_train,y_train,epocks=150,verbose=2)
# Evaluate Our NN
predictions = model.predict_classes(scaled_X_text)
y_test.argmax(axis=1) ## to get the index potion
from sklearn.metrics import confsion_matrix, classification_report, accuracy_score
confusion_matrix(y_test.argmax(axis=1),predictions)
print(classification_report(y_test.argmax(axis=1),predictions)
accuracy_score(y_test.argmax(axis=1),predictions)
model.save('file location\name.h5')
from keras.models import load_model
new_model = load_model('file location\name.h5')
new_model.predict_classes(scaled_X_test)
العودة إلي لغة البرمجة البايثون Python