In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to use Python to predict when your flowers can be used? I believe many inexperienced people are at a loss about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
At the end of the Spring Festival, leaving the embrace of eating and drinking at home, I began an infinite cycle of spending and spending.
Spending gives people a sense of "money". I can't help thinking: when will the peace that I live by spending before I get paid and spend as soon as I get paid? what if I can't afford to spend it?
I decided to use Python to build a model to see when I would face the situation of eating dirt with my current income.
Using the Monte Carlo principle, I decided to establish an income and expenditure model for calculation. Let's first sort out the basics:
1. Basic income: my monthly salary is 1W before tax, and the company will give a bonus of about 1500 yuan per month according to performance.
2. soil-eating conditions: assuming that all the expenses are paid for by the flowers, when the arrears of the monthly expenses are greater than the income that can be spent in the current month, it is necessary to "eat the soil"
3, do not eat soil conditions: preset 120 months (ten years), if ten years have not been able to eat dirt, it means that the wish comes true.
With this logic, I can build an income-expenditure model and implement it in Python code.
Monte Carlo principle, also known as random sampling or statistical test method, uses random numbers (or more common pseudorandom numbers) to solve many calculation problems, and establishes a relationship between the solved problems and a certain probability model. statistical simulation or sampling is realized by computer to obtain the approximate solution of the problem, which is named after the gambling city "Monte Carlo".
1. Establish a monthly income model
In Shanghai, my income is made up of this:
Net income = monthly salary-social insurance and house fund + bonus-personal income tax
* social insurance and house fund's base is the monthly salary, and the personal income tax base is the sum of the monthly salary and bonus after deducting social insurance and house fund.
Shanghai social insurance and house fund payment coefficient:
With the increase of income, the tax rate of personal income tax policy is as follows (before adjustment):
The mathematical model of bonus is set as the normal distribution with the average value of 1500 yuan and the standard deviation of 200 yuan.
Based on the above information, I use Python to establish a model for calculating monthly net income as follows:
Even if I don't know the python language, I can see that I have built a function called "final_income" based on the above information. There are complete codes and tutorials at the end of the article.
two。 Establish a monthly expenditure model
Based on my deep understanding of myself, I simulate which projects I spend each month and how to spend:
Total expenditure = basic living + shopping + entertainment + learning + other
Basic living expenses:
The basic expenditure in Shanghai, 100 a day is fine, and it won't change much. I set a limit of 3000 yuan and 3500 yuan, evenly distributed.
Shopping expenses:
"one cent of the salary is two cents, and half of the shopping." I am a very fond of buying, so the model is set to 5000 yuan as the average, 500 yuan as the standard deviation of the normal distribution.
Entertainment expenses:
It is necessary to meet with friends once a week. It is not too much to spend at least 100 and 300 more at a time. Therefore, the model is set to be uniformly distributed at the limit of 400 yuan and 1200 yuan.
Learning expenses:
Love learning should be my advantage, the price of a course on an online platform ranges from 100 yuan to 500 yuan. So, this can also be set up a uniformly distributed model.
Other expenses:
There will always be some accidents every month, such as losing a wallet when you go out. So, in order to get as close to the reality as possible, I set 500 yuan as the mean and 40 yuan as the standard deviation of the normal distribution model.
Don't laugh, I know this is a standard moonlight clan.
3. Simulate whether the income and expenditure is balanced
With income and expenditure, I can calculate whether I can make ends meet.
First round: do not use staging function
The expenses of the current month must be paid off in full next month. The algorithm model is as follows:
Complete code and tutorials are available at the end of the article.
In order to make the results more accurate, I have carried out 10,000 simulations combined with the above income and expenditure model, and the simulation process is as follows:
The simulation results are as follows:
The Abscissa represents the soil to be eaten in the x-month; the height of the column chart h represents the 1w simulation, and the result happens to be the number of simulations in the x-month.
Obviously, in the case of non-installment loans, I will almost face eating dirt in a year's time, and only six months at the earliest. So, wouldn't it be better to do it by stages?
The second round: allowing staging
The installment is equivalent to apportioning the amount that needs to be repaid for the next few months, reducing the burden of that month, but at the cost of paying a certain amount of interest. At this point, I quickly dug up the interest rate table of the flowers:
Do you understand? If you are good at math, you can calculate it carefully. Now the balance of treasure is 2.5% annual, while the cost is 10% by stages.
If each arrears is repaid by amortization, the algorithm model is as follows:
Complete code and tutorials are available at the end of the article.
Take paying off the debt in three months as an example, after ten thousand simulations, this way has indeed greatly delayed the day of eating dirt. The problem of eating dirt will not be faced until 12 months at the earliest. Wasted for an average of 20 months.
The distribution of six-month, nine-month and twelve-month repayments is as follows:
Note that "eat dirt after an average of XX months" as marked on the intention. The result is very clear, although it has not reached the predetermined standard of not being able to eat dirt for ten years, but the longer the period of time, the longer you can spend without eating dirt, indicating that the time of facing eating dirt can be greatly delayed through overdraft and borrowing.
It was a big surprise for me to squander four years before I went bankrupt. And I believe that with my ability to analyze data, my income will have soared four years later.
But when I opened my home page, I found a problem: my total credit limit is only 15000:
I selected data from one of the 10,000 simulations over a period of 12 months and looked at the total amount owed in the last 12 months on the eve of eating soil:
…… My quota is not enough at all. It seems that eating dirt is inevitable.
4. How to eat soil after considering the quota
This time, I have added a limit to the December algorithm. When the amount owed in the next 12 months is greater than or equal to 15000, the hand will be cut off and the flowers will no longer be used. I intercepted the amount owed at the most likely time when the quota was exhausted and made a simple calculation:
The chart shows that when the quota is exhausted in the 20th month, the total amount of loans to be repaid in the next 12 months is 16544 yuan. In line with the normal quota. You need to pay back 2291 yuan that month, and then decrease it every month.
The debt of more than 2000 yuan is not much, in my current situation, I can certainly afford it. It seems that the amount of spending can control the risk, so that I will not run out of money, nor will I owe a huge amount of money.
After some calculation, I finally realized: there are thousands of roads, the first data. Non-standard expenditure, income two lines of tears.
After reading the above, have you mastered how to use Python to predict your flowers? when can you use it? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.