HomeArtificial IntelligenceHow To Use Artificial Information To Construct a Portfolio Challenge

How To Use Artificial Information To Construct a Portfolio Challenge


How To Use Synthetic Data To Build a Portfolio ProjectHow To Use Synthetic Data To Build a Portfolio Project
Picture by Creator | Canva

 

Introduction

 
Discovering real-world datasets will be difficult as a result of they’re typically non-public (protected), incomplete (lacking options), or costly (behind a paywall). Artificial datasets can resolve these issues by letting you generate the information primarily based in your mission wants.

Artificial knowledge is artificially generated data that mimics real-life datasets. You possibly can management the scale, complexity, and realism of the artificial dataset to tailor it primarily based in your knowledge wants.

On this article, we’ll discover artificial knowledge technology strategies. We are going to then construct a portfolio mission by analyzing the information, making a machine studying mannequin, and utilizing AI to develop an entire portfolio mission with a Streamlit app.

 

Tips on how to Generate Artificial Information

 
Artificial knowledge is usually created randomly, utilizing simulations, guidelines, or AI.

 
How to Generate Synthetic DataHow to Generate Synthetic Data
 

// Technique 1: Random Information Technology

To generate knowledge randomly, we’ll use easy features to create values with none particular guidelines.

It’s helpful for testing, nevertheless it gained’t seize reasonable relationships between options. We’ll do it utilizing NumPy’s random methodology and create a Pandas DataFrame.

import numpy as np
import pandas as pd
np.random.seed(42)
df_random = pd.DataFrame({
    "feature_a": np.random.randint(1, 100, 5),
    "feature_b": np.random.rand(5),
    "feature_c": np.random.selection(["X", "Y", "Z"], 5)
})
df_random.head()

 

Right here is the output.

 
How to Generate Synthetic DataHow to Generate Synthetic Data
 

// Technique 2: Rule-Based mostly Information Technology

Rule-based knowledge technology is a better and extra reasonable methodology than random knowledge technology. It follows a exact system or algorithm. This makes the output purposeful and constant.

In our instance, the scale of a home is instantly linked to its worth. To indicate this clearly, we are going to create a dataset with each measurement and worth. We are going to outline the connection with a system:

Value = measurement × 300 + ε (random noise)

This fashion, you possibly can see the correlation whereas protecting the information moderately reasonable.

np.random.seed(42)
n = 5
measurement = np.random.randint(500, 3500, n)
worth = measurement * 300 + np.random.randint(5000, 20000, n)

df_rule = pd.DataFrame({
    "size_sqft": measurement,
    "price_usd": worth
})
df_rule.head()

 

Right here is the output.

 
How to Generate Synthetic DataHow to Generate Synthetic Data
 

// Technique 3: Simulation-Based mostly Information Technology

The simulation-based knowledge technology methodology combines random variation with guidelines from the actual world. This combine creates datasets that behave like actual ones.

What can we learn about housing?

  • Greater properties often value extra
  • Some cities value greater than others
  • A baseline worth

How can we construct the dataset?

  1. Choose a metropolis at random
  2. Draw a house measurement
  3. Set bedrooms between 1 and 5
  4. Compute the value with a transparent rule

Value rule: We begin with a base worth, add a metropolis worth bump, after which add measurement × charge.

price_usd = base_price × city_bump + sqft × charge

Right here is the code.

import numpy as np
import pandas as pd
rng = np.random.default_rng(42)
CITIES = ["los_angeles", "san_francisco", "san_diego"]
# Metropolis worth bump: greater means pricier metropolis
CITY_BUMP = {"los_angeles": 1.10, "san_francisco": 1.35, "san_diego": 1.00}

def make_data(n_rows=10):
    metropolis = rng.selection(CITIES, measurement=n_rows)
    # Most properties are close to 1,500 sqft, some smaller or bigger
    sqft = rng.regular(1500, 600, n_rows).clip(350, 4500).spherical()
    beds = rng.integers(1, 6, n_rows)

    base = 220_000
    charge = 350  # {dollars} per sqft

    bump = np.array([CITY_BUMP[c] for c in metropolis])
    worth = base * bump + sqft * charge

    return pd.DataFrame({
        "metropolis": metropolis,
        "sqft": sqft.astype(int),
        "beds": beds,
        "price_usd": worth.spherical(0).astype(int),
    })

df = make_data()
df.head()

 

Right here is the output.

 
How do we build the synthetic datasetHow do we build the synthetic dataset
 

// Technique 4: AI-Powered Information Technology

To have AI create your dataset, you want a transparent immediate. AI is highly effective, nevertheless it works finest if you set easy, good guidelines.

Within the following immediate, we are going to embody:

  • Area: What’s the knowledge about?
  • Options: Which columns do we would like?
    • Metropolis, neighborhood, sqft, bedrooms, loos
  • Relationships: How do the options join?
    • Value will depend on metropolis, sqft, bedrooms, and crime index
  • Format: How ought to AI return it?

Right here is the immediate.

 

Generate Python code that creates an artificial California actual property dataset.
The dataset ought to have 10,000 rows with columns: metropolis, neighborhood, latitude, longitude, sqft, bedrooms, loos, lot_sqft, year_built, property_type, has_garage, situation, school_score, crime_index, dist_km_center, price_usd.
Cities: Los Angeles, San Francisco, San Diego, San Jose, Sacramento.
Value ought to depend upon metropolis premium, sqft, bedrooms, loos, lot measurement, college rating, crime index, and distance from metropolis heart.
Embody some random noise, lacking values, and some outliers.
Return the end result as a Pandas DataFrame and put it aside to ‘ca_housing_synth.csv’

 

Let’s use this immediate with ChatGPT.

 
How do we build the synthetic datasetHow do we build the synthetic dataset
 

It returned the dataset as a CSV. Right here is the method that exhibits how ChatGPT created it.

 
How do we build the synthetic datasetHow do we build the synthetic dataset
 

That is probably the most advanced dataset we have now generated by far. Let’s see the primary few rows of this dataset.

 
How do we build the synthetic datasetHow do we build the synthetic dataset

 

Constructing a Portfolio Challenge from Artificial Information

 
We used 4 completely different methods to create an artificial dataset. We are going to use the AI-generated knowledge to construct a portfolio mission.

First, we are going to discover the information, after which construct a machine studying mannequin. Subsequent, we are going to visualize the outcomes with Streamlit by leveraging AI, and within the last step, we are going to uncover which steps to observe to deploy the mannequin to manufacturing.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data

 

// Step 1: Exploring and Understanding the Artificial Dataset

We’ll begin exploring the information by first studying it with pandas and displaying the primary few rows.

df = pd.read_csv("ca_housing_synth.csv")
df.head()

 

Right here is the output.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

The dataset consists of location (metropolis, neighborhood, latitude, longitude) and property particulars (measurement, rooms, 12 months, situation), in addition to the goal worth. Let’s verify the knowledge within the column names, measurement, and size by utilizing the data methodology.

 

Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

We now have 15 columns, with some, like has_garage or dist_km_center, being fairly particular.

 

// Step 2: Mannequin Constructing

The following step is to construct a machine studying mannequin that predicts dwelling costs.

We are going to observe these steps:

Right here is the code.

from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from sklearn.inspection import permutation_importance
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# --- Step 1: Outline columns primarily based on the generated dataset
num_cols = ["sqft", "bedrooms", "bathrooms", "lot_sqft", "year_built", 
            "school_score", "crime_index", "dist_km_center", "latitude", "longitude"]
cat_cols = ["city", "neighborhood", "property_type", "condition", "has_garage"]

# --- Step 2: Cut up the information
X = df.drop(columns=["price_usd"])
y = df["price_usd"]
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

# --- Step 3: Preprocessing pipelines
num_pipe = Pipeline([
    ("imputer", SimpleImputer(strategy="median")),
    ("scaler", StandardScaler())
])
cat_pipe = Pipeline([
    ("imputer", SimpleImputer(strategy="most_frequent")),
    ("encoder", OneHotEncoder(handle_unknown="ignore"))
])

preprocessor = ColumnTransformer([
    ("num", num_pipe, num_cols),
    ("cat", cat_pipe, cat_cols)
])

# --- Step 4: Mannequin
mannequin = RandomForestRegressor(n_estimators=300, random_state=42, n_jobs=-1)

pipeline = Pipeline([
    ("preprocessor", preprocessor),
    ("model", model)
])

# --- Step 5: Practice
pipeline.match(X_train, y_train)

# --- Step 6: Consider
y_pred = pipeline.predict(X_test)
mae = mean_absolute_error(y_test, y_pred)
rmse = mean_squared_error(y_test, y_pred, squared=False)
r2 = r2_score(y_test, y_pred)

print(f"MAE:  {mae:,.0f}")
print(f"RMSE: {rmse:,.0f}")
print(f"R²:   {r2:.3f}")

# --- Step 7: (Non-compulsory) Permutation Significance on a subset for pace
pi = permutation_importance(
    pipeline, X_test.iloc[:1000], y_test.iloc[:1000],
    n_repeats=3, random_state=42, scoring="r2"
)

# --- Step 8: Plot Precise vs Predicted
plt.determine(figsize=(6, 5))
plt.scatter(y_test, y_pred, alpha=0.25)
vmin, vmax = min(y_test.min(), y_pred.min()), max(y_test.max(), y_pred.max())
plt.plot([vmin, vmax], [vmin, vmax], linestyle="--", shade="pink")
plt.xlabel("Precise Value (USD)")
plt.ylabel("Predicted Value (USD)")
plt.title(f"Precise vs Predicted (MAE={mae:,.0f}, RMSE={rmse:,.0f}, R²={r2:.3f})")
plt.tight_layout()
plt.present()

 

Right here is the output.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

Mannequin Efficiency:

  • MAE (85,877 USD): On common, predictions are off by about $86K, which is cheap given the variability in housing costs
  • RMSE (113,512 USD): Bigger errors are penalized extra; RMSE confirms the mannequin handles appreciable deviations pretty effectively
  • R² (0.853): The mannequin explains ~85% of the variance in dwelling costs, displaying robust predictive energy for artificial knowledge

 

// Step 3: Visualize the Information

On this step, we are going to present our course of, together with EDA and mannequin constructing, utilizing the Streamlit dashboard. Why are we utilizing Streamlit? You possibly can construct a Streamlit dashboard shortly and simply deploy it for others to view and work together with.

Utilizing Gemini CLI

To construct the Streamlit utility, we are going to use Gemini CLI.

Gemini CLI is an AI-powered open-source command-line agent. You possibly can write code and construct functions utilizing Gemini CLI. It’s easy and free.

To put in it, use the next command in your terminal.

npm set up -g @google/gemini-cli

 

After putting in, use this code to provoke.

 

It would ask you to log in to your Google account, and then you definitely’ll see the display the place you’ll construct this Streamlit app.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

Constructing a Dashboard

To construct a dashboard, we have to create a immediate that’s tailor-made to your particular knowledge and mission. Within the following immediate, we clarify every part AI must construct a Streamlit dashboard.

Construct a Streamlit app for the California Actual Property dataset by utilizing this dataset ( path-to-dataset )
Right here is the dataset data: 
• Area: California housing — Los Angeles, San Francisco, San Diego, San Jose, Sacramento.
• Location: metropolis, neighborhood, lat, lon, and dist_km_center (haversine to metropolis heart).
• Dwelling options: sqft, beds, baths, lot_sqft, year_built, property_type, has_garage, situation.
• Context: school_score, crime_index.
• Goal: price_usd.
• Value logic: metropolis premium + measurement + rooms + lot measurement + college/crime + distance to heart + property kind + situation + noise.
• Recordsdata you could have: ca_housing_synth.csv (knowledge) and real_estate_model.pkl (educated pipeline).

The Streamlit app ought to have:
• A brief dataset overview part (form, column listing, small preview).
• Sidebar inputs for each mannequin characteristic besides the goal:
- Categorical dropdowns: metropolis, neighborhood, property_type, situation, has_garage.
- Numeric inputs/sliders: lat, lon, sqft, beds, baths, lot_sqft, year_built, school_score, crime_index.
- Auto-compute dist_km_center from the chosen metropolis utilizing the haversine system and that metropolis’s heart.
• A Predict button that:
- Builds a one-row DataFrame with the precise coaching columns (order-safe).
- Calls pipeline.predict(...) from real_estate_model.pkl.
- Shows Estimated Value (USD) with 1000's separators.
• One chart solely: What-if: sqft vs worth line chart (all different inputs mounted to the sidebar values).
- High quality of life: cache mannequin load, primary enter validation, clear labels/tooltips, English UI.

 

Subsequent, Gemini will ask your permission to create this file.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

Let’s approve and proceed. As soon as it has completed coding, it can mechanically open the streamlit dashboard.

If not, go to the working listing of the app.py file and run streamlit run app.py to start out this Streamlit app.

Right here is our Streamlit dashboard.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

When you click on on the information overview, you possibly can see a bit representing the information exploration.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

From the property options on the left-hand facet, we are able to customise the property and make predictions accordingly. This a part of the dashboard represents what we did in mannequin constructing, however with a extra responsive look.

Let’s choose Richmond, San Francisco, single-family, wonderful situation, 1500 sqft, and click on on the “Predict Value” button:

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

The expected worth is $1.24M. Additionally, you possibly can see the precise vs predicted worth within the second graph for the whole dataset when you scroll down.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

You possibly can modify extra options within the left panel, just like the 12 months constructed, crime index, or the variety of loos.

 
Building a Portfolio Project from Synthetic DataBuilding a Portfolio Project from Synthetic Data
 

// Step 4: Deploy the Mannequin

The following step is importing your mannequin to manufacturing. To try this, you possibly can observe these steps:

 

Ultimate Ideas

 
On this article, we have now found completely different strategies to create artificial datasets, resembling random, rule-based, simulation-based, or AI-powered. Subsequent, we’ve constructed a portfolio knowledge mission by ranging from knowledge exploration and constructing a machine studying mannequin.

We additionally used an open-source command-line-based AI agent (Gemini CLI) to develop a dashboard that explores the dataset and predicts home costs primarily based on chosen options, together with the variety of bedrooms, crime index, and sq. footage.

Creating your artificial knowledge helps you to keep away from privateness hurdles, stability your examples, and transfer quick with out expensive knowledge assortment. The draw back is that it could possibly mirror your assumptions and miss real-world quirks. In the event you’re in search of extra inspiration, try this listing of machine studying tasks you can adapt to your portfolio.

Lastly, we checked out methods to add your mannequin to manufacturing utilizing Streamlit Neighborhood Cloud. Go forward and observe these steps to construct and showcase your portfolio mission at the moment!
 
 

Nate Rosidi is a knowledge scientist and in product technique. He is additionally an adjunct professor educating analytics, and is the founding father of StrataScratch, a platform serving to knowledge scientists put together for his or her interviews with actual interview questions from high corporations. Nate writes on the newest developments within the profession market, offers interview recommendation, shares knowledge science tasks, and covers every part SQL.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments