sugitora commited on
Commit
d9161b8
·
1 Parent(s): f389516

Add Car Purchase Simulator files

Browse files
.gradio/flagged/dataset1.csv ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Car Type,Interest Cut (%),Simulation Results,timestamp
2
+ 1,0.01,"{""headers"": [""Car Type"", ""Current Interest Rate (%)"", ""Current Purchase Probability"", ""Current Expected Purchase Amount"", ""New Interest Rate (%)"", ""New Purchase Probability"", ""New Expected Purchase Amount""], ""data"": [[1, 3.9, 0.3, 46.49, 3.89, 0.3002, 46.53]], ""metadata"": null}",2025-02-23 01:10:08.407855
3
+ 2,0.5,"{""headers"": [""Car Type"", ""Current Interest Rate (%)"", ""Current Purchase Probability"", ""Current Expected Purchase Amount"", ""New Interest Rate (%)"", ""New Purchase Probability"", ""New Expected Purchase Amount""], ""data"": [[2, 3.9, 0.3281, 47.23, 3.4, 0.3469, 49.94]], ""metadata"": null}",2025-02-23 01:11:23.857094
4
+ 2,0.5,"{""headers"": [""Car Type"", ""Current Interest Rate (%)"", ""Current Purchase Probability"", ""Current Expected Purchase Amount"", ""New Interest Rate (%)"", ""New Purchase Probability"", ""New Expected Purchase Amount""], ""data"": [[2, 3.9, 0.3281, 47.23, 3.4, 0.3469, 49.94]], ""metadata"": null}",2025-02-23 01:11:27.432303
5
+ 2,0.5,"{""headers"": [""Car Type"", ""Current Interest Rate (%)"", ""Current Purchase Probability"", ""Current Expected Purchase Amount"", ""New Interest Rate (%)"", ""New Purchase Probability"", ""New Expected Purchase Amount""], ""data"": [[2, 3.9, 0.3281, 47.23, 3.4, 0.3469, 49.94]], ""metadata"": null}",2025-02-23 01:11:29.984112
6
+ 2,0.5,"{""headers"": [""Car Type"", ""Current Interest Rate (%)"", ""Current Purchase Probability"", ""Current Expected Purchase Amount"", ""New Interest Rate (%)"", ""New Purchase Probability"", ""New Expected Purchase Amount""], ""data"": [[2, 3.9, 0.3281, 47.23, 3.4, 0.3469, 49.94]], ""metadata"": null}",2025-02-23 01:11:41.982872
20250221_Car_LogitData.csv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11
2
+ 154.9660956,3.9,1.9,0.364,0.45,0.404567463,0.606851194,1.011418657,1.41598612,-0.397073136,-0.115442237
3
+ 143.9424424,3.9,1.9,0.519,0.589,0.453831298,0.680746948,1.134578246,1.588409545,-0.060856621,-0.168159245
4
+ 173.1029233,3.9,1.9,0.473,0.554,0.391369889,0.587054834,0.978424723,1.369794612,-0.120264206,-0.211742269
5
+ 174.6740746,3.9,2.5,0.484,0.625,0.326957931,0.490436897,0.817394828,1.144352759,0.801816352,-0.406712703
6
+ 216.1393818,3.9,1.9,0.445,0.55,0.327608294,0.491412441,0.819020736,1.14662903,0.220874641,-0.263217945
7
+ 246.7452458,3.9,2.9,0.482,0.592,0.286523272,0.429784908,0.716308179,1.002831451,1.45423119,-0.564521768
8
+ 296.1389772,3.9,2.5,0.479,0.516,0.222169897,0.333254846,0.555424743,0.777594641,0.112258804,-0.209057934
9
+ 337.2407599,4.3,1.9,0.524,0.741,0.194013122,0.291019684,0.485032806,0.679045929,1.039755788,-0.334110966
10
+ 463.8277575,4.3,1.9,0.411,0.651,0.158982591,0.238473886,0.397456476,0.556439067,0.605771068,-0.296186149
11
+ 363.3534513,3.9,0.9,0.444,0.771,0.179777895,0.269666843,0.449444739,0.629222634,1.136518144,-0.469911503
Car_Purchase_Results.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Car_Type,Condition,Interest_Rate,Purchase_Probability,Expected_Purchase_Amount
2
+ 8,Current,-7,0.9670268462555028,1934055.6265646983
3
+ 8,After Cut (-2%),0,0.738802882465617,1477607.2425369988
4
+ 1,Current,3.9,0.3000000000183128,600000.0000366255
5
+ 1,After Cut (0.5%),3.4,0.31225955838462643,624519.1167692529
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ # データの読み込み
6
+ data = pd.read_csv("20250221_Car_LogitData.csv")
7
+
8
+ # 結果を格納するデータフレーム
9
+ results_df = pd.DataFrame(columns=["Car_Type", "Condition", "Interest_Rate", "Purchase_Probability", "Expected_Purchase_Amount"])
10
+
11
+ # ロジット関数の定義
12
+ def logistic(x, beta_0, beta_1):
13
+ return 1 / (1 + np.exp(-(beta_0 + beta_1 * x)))
14
+
15
+ # 分析関数
16
+ def perform_analysis(car_type, avg_price, interest_rate, cut_rate):
17
+ global results_df # 既存の結果に追加するためにグローバル変数を利用
18
+
19
+ # 入力値の制限チェック
20
+ if not (1 <= car_type <= 10):
21
+ return "Error: Car_Type must be between 1 and 10."
22
+ if interest_rate < 0 or cut_rate < 0:
23
+ return "Error: Interest rates must be non-negative."
24
+
25
+ # CSVから切片と係数を取得
26
+ beta_0 = data.iloc[int(car_type) - 1, 9] # 10列目(0-indexなので9)
27
+ beta_1 = data.iloc[int(car_type) - 1, 10] # 11列目(0-indexなので10)
28
+
29
+ # 現在の購入確率と期待購入額
30
+ purchase_prob_current = logistic(interest_rate, beta_0, beta_1)
31
+ expected_purchase_current = purchase_prob_current * avg_price
32
+
33
+ # 金利を引き下げた場合の計算(0%未満にならないように制限)
34
+ new_interest_rate = max(0, interest_rate - cut_rate)
35
+ purchase_prob_new = logistic(new_interest_rate, beta_0, beta_1)
36
+ expected_purchase_new = purchase_prob_new * avg_price
37
+
38
+ # 結果を保存
39
+ new_result = pd.DataFrame({
40
+ "Car_Type": [car_type, car_type],
41
+ "Condition": ["Current", f"After Cut ({cut_rate}%)"],
42
+ "Interest_Rate": [interest_rate, new_interest_rate],
43
+ "Purchase_Probability": [purchase_prob_current, purchase_prob_new],
44
+ "Expected_Purchase_Amount": [expected_purchase_current, expected_purchase_new]
45
+ })
46
+
47
+ results_df = pd.concat([results_df, new_result], ignore_index=True)
48
+
49
+ return new_result
50
+
51
+ # CSVダウンロード関数
52
+ def download_results():
53
+ csv_path = "Car_Purchase_Results.csv"
54
+ results_df.to_csv(csv_path, index=False)
55
+ return csv_path
56
+
57
+ # Gradio インターフェースの作成
58
+ with gr.Blocks() as demo:
59
+ gr.Markdown("### 🚗 車種ごとの金利と購入確率の分析ツール(CSVデータからβ0とβ1を自動取得)")
60
+
61
+ with gr.Row():
62
+ car_type = gr.Slider(label="Car Type (1-10)", minimum=1, maximum=10, step=1, value=1)
63
+ avg_price = gr.Number(label="Average Purchase Price", value=2000000)
64
+ interest_rate = gr.Number(label="Current Interest Rate (%)", value=3.9, minimum=0)
65
+ cut_rate = gr.Number(label="Interest Rate Cut (%)", value=0.5, minimum=0)
66
+
67
+ output = gr.Dataframe(label="Analysis Result")
68
+
69
+ analyze_button = gr.Button("Run Analysis")
70
+ analyze_button.click(
71
+ perform_analysis,
72
+ inputs=[car_type, avg_price, interest_rate, cut_rate],
73
+ outputs=output
74
+ )
75
+
76
+ download_button = gr.Button("Download Results as CSV")
77
+ download_file = gr.File()
78
+ download_button.click(download_results, outputs=download_file)
79
+
80
+ # 実行
81
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ pandas
3
+ numpy
space.yml ADDED
File without changes