This repository contains Python code that explores factors influencing time spent on a website using linear regression.
- Age and time spent on the website are positively correlated.
- Chrome users tend to spend longer on the website than Safari users.
- website.csv: Contains data on user age, browser type, and time spent on the website (in seconds).
- linear_regression.py: Python script for analysis, including:
- Loading and exploring data
- Building and fitting linear regression models
- Visualizing results
- Making predictions
- pandas
- numpy
- matplotlib.pyplot
- statsmodels.api
- Install dependencies:
pip install pandas numpy matplotlib statsmodels
- Run the script:
python linear_regression.py
# Load data
website = pd.read_csv('website.csv')
# Model 1: Time vs. Age
model = sm.OLS.from_formula('time_seconds ~ age', website)
results = model.fit()
# Model 2: Time vs. Browser
model = sm.OLS.from_formula('time_seconds ~ browser', website)
results = model.fit()
# Prediction for 40-year-old
pred40 = results.params[0] + results.params[1]*40
Feel free to submit issues or pull requests for improvements or additions.