ML_course/assignment 4/iml_assginment4_unsolved.ipynb
2023-04-27 15:53:45 +02:00

243 lines
4.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"source": [
"Assignment 4 of the course “Introduction to Machine Learning” at the University of Leoben.\n",
"Author: Fotios Lygerakis\n",
"Semester: SS 2022/2023"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Import the libraries"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 1,
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Create the Regression Models"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"class Predictor:\n",
" def __init__(self):\n",
" self.coefficients = None\n",
"\n",
" def fit(self, X, y):\n",
" pass\n",
"\n",
" def predict(self, X):\n",
" pass\n",
"\n",
"class LinearRegression(Predictor):\n",
" pass\n",
"\n",
"class RidgeRegression(Predictor):\n",
" pass\n",
"\n",
"class LassoRegression(Predictor):\n",
" pass"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Data Preprocessing and Data loading functions"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def preprocess(df):\n",
" pass\n",
"\n",
"def train_test_split(X, y, test_size=0.2):\n",
" pass\n",
"\n",
"def load_data():\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [],
"source": [
"# Load the diabetes dataset\n",
"df = pd.read_csv(\"diabetes.csv\")\n",
"\n",
"# Preprocess the dataset\n",
"df = preprocess(df)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Load the data"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [
{
"ename": "TypeError",
"evalue": "cannot unpack non-iterable NoneType object",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[5], line 2\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;66;03m# Load the data\u001B[39;00m\n\u001B[0;32m----> 2\u001B[0m X_train, X_test, y_train, y_test \u001B[38;5;241m=\u001B[39m load_data()\n",
"\u001B[0;31mTypeError\u001B[0m: cannot unpack non-iterable NoneType object"
]
}
],
"source": [
"# Load the data\n",
"X_train, X_test, y_train, y_test = load_data()"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Fit the models"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Fit the linear regression\n",
"linear_regression = LinearRegression()\n",
"linear_regression.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Fit the ridge regression\n",
"ridge_regression = RidgeRegression(alpha=1)\n",
"ridge_regression.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Fit the lasso regression\n",
"lasso_regression = LassoRegression(alpha=1, num_iters=10000, lr=0.001)\n",
"lasso_regression.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"Evaluate the models"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}