In this example we use VerbaGPT to create and compare a neural network model to linear regression while using the famous Abalone dataset 1.
Video:
User question: apply a neural network approach to predict rings. Give me the r2 and compare it to a linear regression approach
VerbaGPT response: ![]()
Cost of query: $0.00*
* Using open-source llama4-maverick model from OpenRouter
Neural network R2: 0.5542
Linear regression R2: 0.5390
VerbaGPT answers the question correctly and gives us what we asked for.
VerbaGPT is a simple yet powerful way to analyze your data. A user can ask any kind of similar question in natural language, and the app does the work to add context, and normalize inputs and outputs so they have a better chance of producing a useful outcome. Check out the full VerbaGPT read-out by click on below.
VerbaGPT Message Window
import pandas as pd
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
# Load data from the database into a DataFrame
query = "SELECT * FROM d_Abalone"
data = pd.read_sql(query, conn)
# One-hot encode the 'Sex' column
enc = OneHotEncoder(sparse=False)
sex_encoded = enc.fit_transform(data[['Sex']])
data = data.join(pd.DataFrame(sex_encoded, columns=enc.get_feature_names_out(['Sex'])))
# Split data into features and target
X = data.drop(['Rings', 'Sex'], axis=1)
y = data['Rings']
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Train a neural network regressor
nn = MLPRegressor(random_state=0)
nn.fit(X_train, y_train)
# Train a linear regression model
lr = LinearRegression()
lr.fit(X_train, y_train)
# Make predictions on the test set using both models
y_pred_nn = nn.predict(X_test)
y_pred_lr = lr.predict(X_test)
# Calculate the R^2 score for both models
r2_nn = r2_score(y_test, y_pred_nn)
r2_lr = r2_score(y_test, y_pred_lr)
print(f"Neural network R^2: {r2_nn:.4f}")
print(f"Linear regression R^2: {r2_lr:.4f}")

Leave a Reply