Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafat3000/glass-classification
Classification data and using ANN model
https://github.com/rafat3000/glass-classification
adam adam-optimizer ann keras labelencoder matloptlib pandas scaler sklearn tensorflow
Last synced: 15 days ago
JSON representation
Classification data and using ANN model
- Host: GitHub
- URL: https://github.com/rafat3000/glass-classification
- Owner: Rafat3000
- Created: 2024-10-09T11:39:49.000Z (30 days ago)
- Default Branch: main
- Last Pushed: 2024-10-09T12:21:38.000Z (30 days ago)
- Last Synced: 2024-10-22T08:51:18.654Z (17 days ago)
- Topics: adam, adam-optimizer, ann, keras, labelencoder, matloptlib, pandas, scaler, sklearn, tensorflow
- Language: Jupyter Notebook
- Homepage: https://www.kaggle.com/code/rafatalzakout/glass-classification/edit
- Size: 78.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![Alt text](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQfphFb2f596llWPYet-MSq84Ri1EhrBmfRUg&s)
# Glass Classification using Neural Network## Dataset Information
The dataset used for this model is related to the classification of different types of glass based on various physical and chemical attributes. The attributes include:
- RI: Refractive Index
- Na: Sodium content
- Mg: Magnesium content
- Al: Aluminum content
- Si: Silicon content
- K: Potassium content
- Ca: Calcium content
- Ba: Barium content
- Fe: Iron content
- Type: Type of glass (Target)## Libraries and Data Loading
```python
import pandas as pd# Load Data
file_path = "/kaggle/input/glass/glass.csv"
data = pd.read_csv(file_path)
data.head()
Sample output:RI Na Mg Al Si K Ca Ba Fe Type
1.5210 13.64 4.49 1.10 71.78 0.06 8.75 0.0 0.0 1
1.5176 13.89 3.60 1.36 72.73 0.48 7.83 0.0 0.0 1
1.5161 13.53 3.55 1.54 72.99 0.39 7.78 0.0 0.0 1
python
Copy code
# Check distribution of the target variable
data['Type'].value_counts()
Output:yaml
Copy code
Type
2 76
1 70
7 29
3 17
5 13
6 9
Name: count, dtype: int64
Data PreprocessingSplitting Features and Target
python
Copy code
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler# Split Features and Target
X = data.drop('Type', axis=1)
y = data['Type'] - 1 # Adjust target to zero-based indexing# Scaling features using Standard Scaler
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)
Building the Neural NetworkUsing TensorFlow and Keras to build an Artificial Neural Network (ANN) for classification.
python
Copy code
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense# Build Sequential model
model = Sequential()# Add input layer and first hidden layer
model.add(Dense(128, input_dim=X_train.shape[1], activation='relu'))# Add more hidden layers
model.add(Dense(128, activation='relu'))
model.add(Dense(128, activation='relu'))
model.add(Dense(256, activation='relu'))
model.add(Dense(128, activation='relu'))# Add output layer with 7 units (for the 7 glass types) and softmax activation
model.add(Dense(7, activation='softmax'))# Model summary
model.summary()
Model Compilation
python
Copy code
# Compile the model
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
Training the Model
python
Copy code
# Train the model
history = model.fit(X_train, y_train, epochs=100, batch_size=10, validation_split=0.2)
Sample training output:arduino
Copy code
Epoch 1/100
14/14 ━━━━━━━━━━━━━━━━━━━━ 2s 25ms/step - accuracy: 0.2974 - loss: 1.8536 - val_accuracy: 0.4286 - val_loss: 1.5107
Epoch 2/100
14/14 ━━━━━━━━━━━━━━━━━━━━ 0s 6ms/step - accuracy: 0.6038 - loss: 1.3588 - val_accuracy: 0.4857 - val_loss: 1.3663
...
Epoch 100/100
14/14 ━━━━━━━━━━━━━━━━━━━━ 0s 6ms/step - accuracy: 0.9985 - loss: 0.0211 - val_accuracy: 0.6857 - val_loss: 4.4292
ConclusionThe model achieves a high training accuracy, though the validation accuracy suggests overfitting. Further hyperparameter tuning or regularization might improve the model's performance on unseen data.
vbnet
Copy codeThis Markdown structure covers the key sections of the code, including data loading, preprocessing, model building, training, and evaluation.