# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/alkhaldieid/models/blob/master/Copy_of_Untitled11.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="BoyxKjpe_2PS" colab_type="code" outputId="1ca189b2-3190-41e2-ce8a-2dc8ec343ce3" colab={"base_uri": "https://localhost:8080/", "height": 124}
from google.colab import drive
drive.mount('/content/gdrive')

# + id="yZtvqXNXAQjD" colab_type="code" outputId="e58c8e80-2a9f-467a-acb5-a3a16b2134a8" colab={"base_uri": "https://localhost:8080/", "height": 34}
# cd /content/gdrive/My\ Drive


# + id="dbzS2TNJBeSB" colab_type="code" outputId="70cb0ac6-4975-45a8-d965-2de182d2c502" colab={"base_uri": "https://localhost:8080/", "height": 208}
# !pip install pandas
# !pip install request


# + id="70mQmcV-AQm-" colab_type="code" colab={}
import pandas as pd
data = pd.read_excel('1.0 Deck Structure.xlsx', index_col=0)

# + id="vByOKnwQAvUY" colab_type="code" outputId="09ec88c2-2594-4de5-ef03-78f8cdd7c2c6" colab={"base_uri": "https://localhost:8080/", "height": 473}
data

# + id="QPTQJgtdNThV" colab_type="code" outputId="504b77cd-384f-4767-8f1b-8ce17b560c78" colab={"base_uri": "https://localhost:8080/", "height": 34}
data.shape

# + id="kwqaDWSyJoMz" colab_type="code" outputId="032e6a71-d523-4868-96f8-4db5e8360b63" colab={"base_uri": "https://localhost:8080/", "height": 243}
labels = data['Deck Condition']
print(labels)

# + id="0ajV-87rJz7r" colab_type="code" colab={}
columns = list(data)

# + id="14p2rkApK1z2" colab_type="code" outputId="2ed8f075-3a59-4969-cea4-68f88a334240" colab={"base_uri": "https://localhost:8080/", "height": 260}
columns

# + id="uinld21JK3UC" colab_type="code" outputId="9b59d6ef-a753-4a15-c536-7bd311818d77" colab={"base_uri": "https://localhost:8080/", "height": 139}
npdata = data.values
print(npdata)

# + id="9vD9MuV7LyIH" colab_type="code" outputId="654f9e79-044e-4081-b05f-65c38c5a203c" colab={"base_uri": "https://localhost:8080/", "height": 34}
import numpy as np
np.shape(npdata)

# + id="octovYuYL54l" colab_type="code" outputId="481bba75-32ac-4fd5-c095-6e21533319c8" colab={"base_uri": "https://localhost:8080/", "height": 34}
len(columns)

# + id="hYt7KMQJMMh1" colab_type="code" outputId="43cc49e4-f7d2-4975-c69d-a6b2672bc05e" colab={"base_uri": "https://localhost:8080/", "height": 34}
unnumData = npdata[:,1:]
print(np.shape(unnumData))

# + id="hX0tKb8qMtRr" colab_type="code" outputId="e388750c-748b-49c5-b89e-9c3af7d74982" colab={"base_uri": "https://localhost:8080/", "height": 139}
unnumData

# + id="-mRzkI_ZMxIl" colab_type="code" outputId="8385fc97-800a-4a21-9eca-5c5c90e1255a" colab={"base_uri": "https://localhost:8080/", "height": 52}
unnumData[0]

# + id="wxUOZKkYM0VF" colab_type="code" outputId="fa500a20-aab7-42fd-eeae-f0d0f6e728f2" colab={"base_uri": "https://localhost:8080/", "height": 156}
unnumData92 = unnumData[:2875,:]
print(unnumData92)
print(np.shape(unnumData))

# + id="r7LZQ596Nk1t" colab_type="code" outputId="6a01abc8-a6a2-49ec-b47e-6ba9a3732b23" colab={"base_uri": "https://localhost:8080/", "height": 139}
unnumFeatures92 = np.delete(unnumData92, [10], axis=1)
print(unnumFeatures92)

# + id="FQlbJAifYFis" colab_type="code" outputId="28cea997-5d5e-405d-b951-056bc1605f91" colab={"base_uri": "https://localhost:8080/", "height": 72}
unclean = []
for i in range(np.shape(unnumFeatures92)[0]):
  for j in range(np.shape(unnumFeatures92)[1]):
    if isinstance(unnumFeatures92[i,j], str):
      unclean.append([i,j])
print(unclean)
len(unclean)

# + id="eyLLSs7-ZXTg" colab_type="code" outputId="5e971404-2b97-477b-f6f7-6a5988050674" colab={"base_uri": "https://localhost:8080/", "height": 1000}
for indeces in unclean:
  print(unnumFeatures92[indeces[0],:])

# + id="bwlDGsdHPZWd" colab_type="code" outputId="75722295-b8eb-4463-f1ac-907a4071626c" colab={"base_uri": "https://localhost:8080/", "height": 34}
print(len(unclean))

# + id="F7HZ7bTuPhx-" colab_type="code" outputId="4bbc787e-f4e3-486f-b797-1cb1a4643fdf" colab={"base_uri": "https://localhost:8080/", "height": 72}
uncleanRows=[]
for i in range(len(unclean)):
  uncleanRows.append(unclean[i][0])
print(len(uncleanRows))
print(uncleanRows)

# + id="He2Z4lepRCOY" colab_type="code" outputId="15dc1f30-fbab-404b-a553-f87574fa1a12" colab={"base_uri": "https://localhost:8080/", "height": 34}
cleanFeatures92 = np.delete(unnumFeatures92, uncleanRows, axis= 0)
print(np.shape(cleanFeatures92))

# + id="lW1G9EvDRhp3" colab_type="code" outputId="f6482630-11c5-4db9-b158-0cbaba1c87ae" colab={"base_uri": "https://localhost:8080/", "height": 1000}
for i in range(len(cleanFeatures92)):
  print((cleanFeatures92[i,:]))

# + id="u9qZlJgCRkvF" colab_type="code" outputId="848094e8-87a2-44aa-b7ab-8fef415d5630" colab={"base_uri": "https://localhost:8080/", "height": 52}
unclean_labels = unnumData92[:,10]
print(len(unclean_labels))
cleanLabels92 = np.delete(unclean_labels, uncleanRows, axis=0)
print(len(cleanLabels92))

# + id="cJXlWk0jTZED" colab_type="code" colab={}
cleanData = np.array(list(zip(cleanFeatures92,cleanLabels92)))

# + id="MY5HXA0lSJdz" colab_type="code" outputId="d7b4181b-8837-4a1a-c710-8917053a7715" colab={"base_uri": "https://localhost:8080/", "height": 34}
np.shape(cleanData)

# + id="Skc7ED9dVFG-" colab_type="code" outputId="7bc0c3dd-4415-488e-8913-28416d221856" colab={"base_uri": "https://localhost:8080/", "height": 278}
cleanData

# + id="0F89B_OvVIb3" colab_type="code" outputId="ec573921-1005-40d8-dd54-b828ebc01eb8" colab={"base_uri": "https://localhost:8080/", "height": 34}
cleanData[0][1]


# + id="J1g0G6sZVTWB" colab_type="code" outputId="cb97232b-d2d1-4ab1-c743-52af3d29c401" colab={"base_uri": "https://localhost:8080/", "height": 52}
cleanData[0][0]


# + id="yf0dDqHCVkXq" colab_type="code" colab={}
import keras
categorical_labels=keras.utils.to_categorical(cleanLabels92)


# + id="wncdPq-fgaY4" colab_type="code" outputId="60ccf4fe-80ae-4e7a-a388-f2706f04fe61" colab={"base_uri": "https://localhost:8080/", "height": 34}
training_data = np.array(list(zip(cleanFeatures92,categorical_labels)))
print(np.shape(training_data))

# + id="o9ywbIylgp_T" colab_type="code" outputId="7189129f-eaf1-4faf-b99b-742aeece09ad" colab={"base_uri": "https://localhost:8080/", "height": 34}
np.shape(training_data)

# + id="XSnWNHMrhtM3" colab_type="code" colab={}
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam
from keras import metrics

# + id="cGK-4ib5hDCT" colab_type="code" outputId="fa612781-e0d3-43aa-e3aa-3175db121af9" colab={"base_uri": "https://localhost:8080/", "height": 52}
#simple keras model
t_model = Sequential()
t_model.add(Dense(100, activation="relu"))
t_model.add(Dense(50, activation="relu"))
t_model.add(Dense(10))
t_model.compile(
    loss="mean_squared_error",
    optimizer=Adam(lr=0.001),
    metrics=[metrics.mae])

# + id="J0tSN8zuhU6P" colab_type="code" colab={}
epochs = 500
batch = 128

# + id="G9XewgyYjuH4" colab_type="code" outputId="a0a89ea3-15a3-4b59-d83b-6031644868c0" colab={"base_uri": "https://localhost:8080/", "height": 295}
training_data

# + id="lKpNZKQQjR2V" colab_type="code" outputId="fded84a2-c2dd-42d5-d198-8b36543195ab" colab={"base_uri": "https://localhost:8080/", "height": 1000}
history = t_model.fit(
    x = cleanFeatures92,
    y = categorical_labels,
    batch_size=batch,
    epochs=epochs,
    shuffle=True,
    verbose=1,
    callbacks=[]
)


# + id="ZCg-yTv5kly3" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered