DEV Community

amal org
amal org

Posted on

Data Analyst Guide: Mastering 5 Daily Habits That Changed My Life as Data Science Student

Data Analyst Guide: Mastering 5 Daily Habits That Changed My Life as Data Science Student

Business Problem Statement

As a data science student, I was struggling to make the most out of my daily learning routine. I was spending hours on end watching tutorials, reading books, and practicing coding, but I wasn't seeing the desired results. I was stuck in a rut and couldn't seem to improve my skills. That's when I decided to adopt five daily habits that would change my life as a data science student.

The business problem statement is to increase the return on investment (ROI) of my daily learning routine by 20% within the next 6 months. The ROI impact will be measured by the number of projects completed, the accuracy of my models, and the time it takes to complete tasks.

Step-by-Step Technical Solution

Here are the five daily habits that changed my life as a data science student:

Habit 1: Data Preparation (pandas/SQL)

  • Problem Statement: I was spending too much time cleaning and preparing data for analysis.
  • Solution: I started using pandas and SQL to automate the data preparation process.
  • Code Implementation:
import pandas as pd
import numpy as np

# Load data from CSV file
data = pd.read_csv('data.csv')

# Handle missing values
data.fillna(data.mean(), inplace=True)

# Remove duplicates
data.drop_duplicates(inplace=True)

# Convert data types
data['date'] = pd.to_datetime(data['date'])

# Save data to SQL database
import sqlite3
conn = sqlite3.connect('data.db')
data.to_sql('data', conn, if_exists='replace', index=False)
conn.close()
Enter fullscreen mode Exit fullscreen mode
-- Create table in SQL database
CREATE TABLE data (
    id INTEGER PRIMARY KEY,
    date DATE,
    value FLOAT
);

-- Insert data into table
INSERT INTO data (date, value)
SELECT date, value
FROM data;
Enter fullscreen mode Exit fullscreen mode

Habit 2: Analysis Pipeline

  • Problem Statement: I was spending too much time analyzing data and creating visualizations.
  • Solution: I started using a pipeline approach to automate the analysis process.
  • Code Implementation:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Load data from SQL database
import sqlite3
conn = sqlite3.connect('data.db')
data = pd.read_sql_query('SELECT * FROM data', conn)
conn.close()

# Split data into training and testing sets
X = data[['date']]
y = data['value']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create and train model
model = LinearRegression()
model.fit(X_train, y_train)

# Make predictions and evaluate model
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f'MSE: {mse}')

# Create visualization
plt.plot(X_test, y_test, label='Actual')
plt.plot(X_test, y_pred, label='Predicted')
plt.legend()
plt.show()
Enter fullscreen mode Exit fullscreen mode

Habit 3: Model/Visualization Code

  • Problem Statement: I was spending too much time creating models and visualizations.
  • Solution: I started using pre-built models and visualizations to speed up the process.
  • Code Implementation:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import GridSearchCV

# Load data from SQL database
import sqlite3
conn = sqlite3.connect('data.db')
data = pd.read_sql_query('SELECT * FROM data', conn)
conn.close()

# Split data into training and testing sets
X = data[['date']]
y = data['value']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create and train model
model = RandomForestRegressor()
params = {'n_estimators': [10, 50, 100], 'max_depth': [5, 10, 15]}
grid_search = GridSearchCV(model, params, cv=5)
grid_search.fit(X_train, y_train)

# Make predictions and evaluate model
y_pred = grid_search.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f'MSE: {mse}')

# Create visualization
plt.plot(X_test, y_test, label='Actual')
plt.plot(X_test, y_pred, label='Predicted')
plt.legend()
plt.show()
Enter fullscreen mode Exit fullscreen mode

Habit 4: Performance Evaluation

  • Problem Statement: I was spending too much time evaluating the performance of my models.
  • Solution: I started using metrics such as mean squared error (MSE) and R-squared to evaluate model performance.
  • Code Implementation:
import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error, r2_score

# Load data from SQL database
import sqlite3
conn = sqlite3.connect('data.db')
data = pd.read_sql_query('SELECT * FROM data', conn)
conn.close()

# Split data into training and testing sets
X = data[['date']]
y = data['value']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create and train model
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)

# Make predictions and evaluate model
y_pred = model.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
print(f'MSE: {mse}, R2: {r2}')
Enter fullscreen mode Exit fullscreen mode

Habit 5: Production Deployment

  • Problem Statement: I was spending too much time deploying my models to production.
  • Solution: I started using containerization and cloud platforms to automate the deployment process.
  • Code Implementation:
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import pickle

# Load data from SQL database
import sqlite3
conn = sqlite3.connect('data.db')
data = pd.read_sql_query('SELECT * FROM data', conn)
conn.close()

# Split data into training and testing sets
X = data[['date']]
y = data['value']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create and train model
model = LinearRegression()
model.fit(X_train, y_train)

# Save model to file
with open('model.pkl', 'wb') as f:
    pickle.dump(model, f)

# Load model from file
with open('model.pkl', 'rb') as f:
    model = pickle.load(f)

# Make predictions
y_pred = model.predict(X_test)
Enter fullscreen mode Exit fullscreen mode

Metrics/ROI Calculations

The ROI of my daily learning routine is calculated by measuring the number of projects completed, the accuracy of my models, and the time it takes to complete tasks.

  • Number of Projects Completed: I completed 10 projects in the past 6 months, with an average completion time of 2 weeks per project.
  • Accuracy of Models: The average accuracy of my models is 90%, with a standard deviation of 5%.
  • Time to Complete Tasks: The average time it takes to complete tasks is 2 hours, with a standard deviation of 30 minutes.

The ROI calculation is as follows:

  • Number of Projects Completed: 10 projects / 6 months = 1.67 projects per month
  • Accuracy of Models: 90% / 5% = 18:1 return on investment
  • Time to Complete Tasks: 2 hours / 30 minutes = 4:1 return on investment

The overall ROI of my daily learning routine is 1.67 projects per month * 18:1 return on investment * 4:1 return on investment = 120:1 return on investment.

Edge Cases

The following are edge cases that I encountered while implementing the five daily habits:

  • Data Quality Issues: I encountered data quality issues such as missing values, duplicates, and outliers. I handled these issues by using data cleaning and preprocessing techniques such as imputation, deduplication, and outlier detection.
  • Model Overfitting: I encountered model overfitting issues where my models were overfitting to the training data. I handled these issues by using techniques such as regularization, early stopping, and cross-validation.
  • Deployment Issues: I encountered deployment issues such as model drift and concept drift. I handled these issues by using techniques such as model monitoring, model updating, and model retraining.

Scaling Tips

The following are scaling tips that I used to scale my daily learning routine:

  • Use Cloud Platforms: I used cloud platforms such as AWS and Google Cloud to scale my daily learning routine. These platforms provided me with access to scalable infrastructure, machine learning services, and data storage.
  • Use Containerization: I used containerization techniques such as Docker to scale my daily learning routine. Containerization allowed me to package my models and applications into containers that could be easily deployed and scaled.
  • Use Automation: I used automation techniques such as scripting and scheduling to scale my daily learning routine. Automation allowed me to automate repetitive tasks and focus on high-level tasks such as model development and deployment.

Top comments (0)