# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="0eXVUpoKZwNr"
# #Task 1 :Try Linear Regression just using numpy (Without Tensorflow/Pytorch or other torch library).

# + id="W6NK3ltgYHJ3" executionInfo={"status": "ok", "timestamp": 1630477588788, "user_tz": -330, "elapsed": 1397, "user": {"displayName": "dhaval karen", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}}
import numpy as np
from sklearn.linear_model import LinearRegression

# + colab={"base_uri": "https://localhost:8080/"} id="lHVGJ7nNYHJ4" executionInfo={"status": "ok", "timestamp": 1630477591687, "user_tz": -330, "elapsed": 32, "user": {"displayName": "dhaval karen", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}} outputId="40601b94-7325-4fd6-ecb5-57dc3f2936ef"
inputs = np.array([[73, 67, 43],
                    [91, 88, 64],
                    [87, 134, 58],
                    [102, 43, 37],
                    [69, 96, 70],
                    [73, 67, 43],
                    [91, 88, 64],
                    [87, 134, 58],
                    [102, 43, 37],
                    [69, 96, 70],
                    [73, 67, 43], 
                    [91, 88, 64], 
                    [87, 134, 58], 
                    [102, 43, 37], 
                    [69, 96, 70]], dtype='float32')
print(inputs.shape)

# + id="3NunoIBCYHJ6" executionInfo={"status": "ok", "timestamp": 1630477595596, "user_tz": -330, "elapsed": 10, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}}
targets = np.array([[56, 70], [81, 101], [119, 133], [22, 37], [103, 119],
[56, 70], [81, 101], [119, 133], [22, 37], [103, 119],
[56, 70], [81, 101], [119, 133], [22, 37], [103, 119]], dtype='float32')

# + id="GGlX1RMbYHJ6" executionInfo={"status": "ok", "timestamp": 1630477599362, "user_tz": -330, "elapsed": 382, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}}
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(inputs,targets,test_size=0.4, random_state=58)

# + colab={"base_uri": "https://localhost:8080/"} id="_7ez_dU0YHJ7" executionInfo={"status": "ok", "timestamp": 1630477601550, "user_tz": -330, "elapsed": 27, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}} outputId="ac06cf40-b1fc-4e9b-b5ae-cee0783dfc26"
reg = LinearRegression().fit(x_train,y_train)
print(reg)

# + colab={"base_uri": "https://localhost:8080/"} id="qisKJXBxYHJ8" executionInfo={"status": "ok", "timestamp": 1630477605536, "user_tz": -330, "elapsed": 346, "user": {"displayName": "<NAME>", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}} outputId="2dcbfde6-5e24-4d62-d17a-486e2388f09c"
print(reg.intercept_)
print(reg.coef_)

# + colab={"base_uri": "https://localhost:8080/"} id="-wIb51_WYHJ9" executionInfo={"status": "ok", "timestamp": 1630477610002, "user_tz": -330, "elapsed": 418, "user": {"displayName": "dhaval karen", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}} outputId="4b8bf666-7d6c-40f0-90c3-66593b03a7ff"
y_pred = reg.predict(x_test)
print(y_pred,"\n")
print(y_test)

# + colab={"base_uri": "https://localhost:8080/"} id="yrVwSpngYHJ-" executionInfo={"status": "ok", "timestamp": 1630477619116, "user_tz": -330, "elapsed": 360, "user": {"displayName": "dhaval karen", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvY6o4MuHT6YUeaqCq-6tAM61bz0NJJ6eXkl6VmA=s64", "userId": "03115065192551383929"}} outputId="723dfcb3-320e-4a31-fc0e-e30beb135126"
from sklearn import metrics
print('\n Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))

StarcoderdataJupyterScriptsDedupFiltered