Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import numpy as np | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.linear_model import LinearRegression | |
| import streamlit as st | |
| import plotly.figure_factory as ff | |
| st.title('A Simple Profit Prediction 💵') | |
| st.image('https://assets2.ignimgs.com/2013/11/12/the-hobbit-bilbo-gold-1280jpg-e9649d_160w.jpg?width=1280') | |
| st.write('### Data ') | |
| df = pd.read_csv("https://raw.githubusercontent.com/amankharwal/Website-data/master/Startups.csv") | |
| st.dataframe(df) | |
| st.write('This data is about the R&D spend, Administration cost, Marketing Spend, State of operation, and the historical profit generated by 50 startups.') | |
| df_graph = df.groupby('State')['Profit'].sum().reset_index() | |
| st.write("### Total Profits by State") | |
| st.bar_chart(df_graph, x="State", y="Profit") | |
| numeric_columns = df.select_dtypes(include=['float64', 'int64']) | |
| corr_matrix = numeric_columns.corr() | |
| fig = ff.create_annotated_heatmap(z=corr_matrix.values, | |
| x=numeric_columns.columns.tolist(), | |
| y=numeric_columns.columns.tolist(), | |
| annotation_text=corr_matrix.round(2).values) | |
| fig.update_layout() | |
| st.write("### Correlation Heatmap") | |
| st.plotly_chart(fig) | |
| st.write('There is a clear correlation between R&D and Profit.Also, administration sucks.') | |
| #model | |
| st.write('### Model Training') | |
| x = df[["R&D Spend", "Administration", "Marketing Spend"]] | |
| y = df["Profit"] | |
| x = x.to_numpy() | |
| y = y.to_numpy() | |
| y = y.reshape(-1, 1) | |
| from sklearn.model_selection import train_test_split | |
| xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42) | |
| from sklearn.linear_model import LinearRegression | |
| model = LinearRegression() | |
| model.fit(xtrain, ytrain) | |
| st.write(f"I after train test split, I have defined a LinerRegression Model. It's r2 score is. {model.score(xtest, ytest)}, meaning 90% accuracy") | |
| st.write('### Using It') | |
| st.write('Change the expenditures to see the difference in profit.') | |
| # Input boxes for features | |
| feature1 = st.number_input('R&D Spend', value=100000) | |
| feature2 = st.number_input('Administration Spend', value=100000) | |
| feature3 = st.number_input('Marketing Spend', value=100000) | |
| features = np.array([[feature1, feature2, feature3]]) | |
| # Assuming 'model' is your trained model | |
| prediction = model.predict(features) | |
| st.write(f'Predicted Profit: {prediction[0]}') | |
| st.write('### Conclusion') | |
| st.write('This model abides the expenditure/profit relation of the 50 startups in this dataset. If you are one of them, this app will be useful. Otherwise, to make a more general model, we simply need more data.') |