Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Yrstruly2021
Helper V
Helper V

Python Evaluation

Can anybody with Python experience test my code and let's compare answers/notes, please?

 

import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow.keras import layers

abalone_train = pd.read_csv(
r"C:\Users\Anthony.DESKTOP-ES5HL78\Downloads\abalone.data",
sep=“,”,
names=[
“Sex”, “Length”, “Diameter”, “Height”, “Whole weight”,
“Shucked weight”, “Viscera weight”, “Shell weight”, “Age”
]
)

# Perform one-hot encoding for the ‘Sex’ column

abalone_train = pd.get_dummies(abalone_train, columns=[‘Sex’])

abalone_features = abalone_train.copy()
abalone_labels = abalone_features.pop(‘Age’)

# Convert to numpy array and float32 data type

abalone_features = abalone_features.astype(‘float32’)
abalone_labels = abalone_labels.astype(‘float32’)

# Create a sequential model

model = tf.keras.Sequential([
layers.Dense(64, activation=‘relu’),
layers.Dense(1)
])

# Compile the model

model.compile(optimizer=tf.keras.optimizers.Adam(), loss=tf.keras.losses.MeanSquaredError())

# Fit the model

history = model.fit(abalone_features, abalone_labels, epochs=10, verbose=0)

# Print history and model summary

print(history.history)
model.summary()

{ [74.98324584960938, 12.322690963745117, 7.765621185302734, 7.502653121948242, 7.229104518890381, 6.997042179107666, 6.799757957458496, 6.645227432250977, 6.521533489227295, 6.418800354003906]}
Model: “sequential”

---

# Layer (type) Output Shape Param #

dense (Dense) (None, 64) 704

dense_1 (Dense) (None, 1) 65

=================================================================
Total params: 769
Trainable params: 769
Non-trainable params: 0

## Data for this Question: [https://drive.google.com/file/d/1iSgWZUK…sp=sharing](https://drive.google.com/file/d/1iSgWZUK23Gw6R-2rUkKeEOl6BIwms8L8/view?usp=sharing)

0 REPLIES 0

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.