<jupyter_start><jupyter_text>Bin app type<jupyter_code>replace_app= list(app_type[app_type < 500].index)

#repace in DataFrame
for app in replace_app:
  charity_df["APPLICATION_TYPE"]= charity_df["APPLICATION_TYPE"].replace(app, "Other")

charity_df["APPLICATION_TYPE"].value_counts()<jupyter_output><empty_output><jupyter_text>Bin Classification<jupyter_code>class_type= charity_df["CLASSIFICATION"].value_counts()

class_type.plot.density()
replace_class= list(class_type[class_type < 1000].index)

#repace in DataFrame
for app in replace_class:
  charity_df["CLASSIFICATION"]= charity_df["CLASSIFICATION"].replace(app, "Other")

charity_df["CLASSIFICATION"].value_counts()

charity_df<jupyter_output><empty_output><jupyter_text>Standarization<jupyter_code>#Create the OneHotEncoder instance

from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder(sparse = False)

#fut the encoder and produce encoded DataFrame
encode_df= pd.DataFrame(enc.fit_transform(charity_df[cat].values.reshape(-1,1)))

#Rename encoded columns

encode_df.columns = enc.get_feature_names(['GROUP'])
charity_df =charity_df.merge(encode_df, left_index= True, right_index= True).drop(cat,1)
charity_df<jupyter_output><empty_output><jupyter_text>Split to testing and traning<jupyter_code># Split our preprocessed data into our features and target arrays
y = charity_df["IS_SUCCESSFUL"].values
x = charity_df.drop(['IS_SUCCESSFUL'],1).values

# Split 

X_train, X_test, y_train, y_test = train_test_split(x, y)
# Create a StandardScaler instance
scaler = StandardScaler()

# Fit the StandardScaler
X_scaler = scaler.fit(X_train)

# Scale the data
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)
number_input_features = len(X_train_scaled[0])
number_input_features
# Define the model - deep neural net
number_input_features = len(X_train_scaled[0])

hidden_nodes_layer1= 90

nn = tf.keras.models.Sequential()

#first hidden layer

nn.add(tf.keras.layers.Dense(units= hidden_nodes_layer1, input_dim= number_input_features, activation= "relu"))


# Output layer
nn.add(tf.keras.layers.Dense(units=1, activation="sigmoid"))

# Check the structure of the model
nn.summary()
# Compile the model
nn.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])
# Train the model
fit_model = nn.fit(X_train_scaled ,y_train,epochs=100)
# Evaluate the model using the test data
model_loss, model_accuracy = nn.evaluate(X_test_scaled,y_test,verbose=2)
print(f"Loss: {model_loss}, Accuracy: {model_accuracy}")
tf.keras.backend.clear_session()<jupyter_output><empty_output><jupyter_text>Optimization<jupyter_code># Define the model - deep neural net
number_input_features = len(X_train[0])

hidden_nodes_layer1= 60
hidden_nodes_layer2= 40

nn = tf.keras.models.Sequential()

#first hidden layer

nn.add(tf.keras.layers.Dense(units= hidden_nodes_layer1, input_dim= number_input_features, activation= "linear"))

# Second hidden layer
nn.add(tf.keras.layers.Dense(units=hidden_nodes_layer2, activation="relu"))

# Third hidden layer
nn.add(tf.keras.layers.Dense(units=hidden_nodes_layer3, activation="relu"))
# Output layer
nn.add(tf.keras.layers.Dense(units=1, activation="sigmoid"))

# Check the structure of the model
nn.summary()
# Compile the model
nn.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])
# Train the model
fit_model = nn.fit(X_train_scaled,y_train,epochs=100)
# Evaluate the model using the test data
model_loss, model_accuracy = nn.evaluate(X_test_scaled,y_test,verbose=2)
print(f"Loss: {model_loss}, Accuracy: {model_accuracy}")<jupyter_output>268/268 - 0s - loss: 0.6937 - accuracy: 0.5345
Loss: 0.6937354207038879, Accuracy: 0.5345229506492615
{'fraction_non_alphanumeric': 0.1182014001077006, 'fraction_numerical': 0.023694130317716746, 'mean_word_length': 8.2875, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '472715', 'license': 'MIT', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1327, 'n_words': 248, 'path': 'AlphabetSoupChallenge.ipynb', 'repo_name': 'anapereda/DeepNeuralNetworks', 'size': '3714'}