# -*- coding: utf-8 -*- """d7.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/1Z4csahRmsC2REaymzcm_UZxrUpVgUsIv """ 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 r2_score, mean_squared_error from sklearn.compose import ColumnTransformer from sklearn.preprocessing import OneHotEncoder, StandardScaler from sklearn.pipeline import Pipeline df=pd.read_excel("cars.xls") df.info() #VERİ ÖN İŞLEME X = df.drop('Price',axis=1) y=df['Price'] X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42) preprocess=ColumnTransformer( transformers=[ ('num',StandardScaler(),['Mileage','Cylinder','Liter','Doors']), ('cat',OneHotEncoder(),['Make','Model','Trim','Type']) ] ) my_model=LinearRegression() #Pipeline Tanımla pipe=Pipeline(steps=[('preprocessor',preprocess),('model',my_model)]) pipe.fit(X_train,y_train) y_pred=pipe.predict(X_test) print('RMSE',mean_squared_error(y_test,y_pred)**0.5) print('R2',r2_score(y_test,y_pred)) #pip install streamlit import streamlit as st def price(make, model,trim,mileage,car_type,cylinder,liter,doors, curise,sound,leather): input_data=pd.DataFrame({'Make':[make], 'Model':[model], 'Trim':[trim], 'Mileage':[mileage], 'Type':[car_type], 'Cylinder':[cylinder], 'Liter':[liter], 'Doors':[doors], 'Cruise':[cruise], 'Sound':[sound], 'Leather':[leather]}) # The following line was indented too far, causing the error. prediction=pipe.predict(input_data)[0] return prediction st.title('2.El Araba Fiyat Tahmin @tugbaksu') st.write('Arabanın özelliklerini seçiniz') make=st.selectbox('Marka',df['Make'].unique()) model=st.selectbox('Model',df[df['Make']==make]['Model'].unique()) trim=st.selectbox('Trim',df[(df['Make']==make) &(df['Model']==model)]['Trim'].unique()) mileage=st.number_input('Kilometre',100,200000) car_type=st.selectbox('Araç Tipi',df[(df['Make']==make) &(df['Model']==model)&(df['Trim']==trim)]['Type'].unique()) cylinder=st.selectbox('Cylinder',df['Cylinder'].unique()) liter=st.number_input('Yakıt hacmi',1,10) doors=st.selectbox('Kapı sayısı',df['Doors'].unique()) cruise=st.radio('Hız Sbt.',[True,False]) sound=st.radio('Ses Sis.',[True,False]) leather=st.radio('Deri döşeme.',[True,False]) if st.button('Tahmin'): pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather) st.write('Fiyat:$', round(pred[0],2))