File size: 814 Bytes
fd9dd7f
 
 
 
 
 
27aadf0
fd9dd7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import gradio as gr

ad_data = pd.read_csv("Advertising.csv")
ad_data.drop("Unnamed: 0", axis = 1, inplace = True)

X = ad_data.drop("sales", axis = 1)
y = ad_data["sales"]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(X_train, y_train)

def show_prediction(tv, radio, newspaper):
    new_df = pd.DataFrame({"TV" : tv, "radio" : radio, "newspaper" : newspaper}, index = [0])
    y_pred = lr.predict(new_df)
    return y_pred

demo = gr.Interface(
    show_prediction,
    [
        "number",
        "number",
        "number"
    ],
    "number"
)
demo.launch()