辅导GBA 464编程、 写作c/c++,Python编程

” 辅导GBA 464编程、 写作c/c++,Python编程GBA 464: Assignment 3Yufeng HuangSeptember 29, 20201 ObjectiveThe general goal of this task is that we try to distinguish potential high-value consumers and separatethem from low-value consumers. Recency, frequency and monetary value (RFM) are 3 factorsthat we can calculate and use to do the targeting. In this assignment, we will work with a sampledataset from a company called CDNOW, to try and figure out the potential value of a consumer ina given month, using only historical data prior to this month. We will then classify the sample bythe RFM index we generated and see how much it is related to actual consumer spending.2 Loading the data [20%]You can obtain the dataset via the following link: httpss://dl.dropboxusercontent.com/s/xxfloksp0968mgu/CDNOW_sample.txtor directly on Blackboard. Note that the Data is stored in fixed format, meaning that each variablestarts at a fixed column in the text file. Ive written the code for reading the data. Basically, Iuse the function read.fwf() to read the data.In the raw data, the first two variables are individual consumer identifiers. The second oneis a re-coded version of the first one. For simplicity, we drop the first variable and only use therecoded ID as identifiers. Ive already written this part as well. After dropping the first column in1the original data, the remaining columns are individual ID ($id), date of the trip ($date), purchasequantity (i.e. number of CDs purchased, $qty) and total expenditure (in dollar values, $expd).Our next step is to Aggregate the data into individual-month level, so keys should be $id, $year,and $month. During this aggregation process, we should sum up quantity and expenditure for eachconsumer in each month. You also need how many trips (construct $trips) the individual has beento the shop. Assign the collapsed data (again, on the key of $id, $year and $month) to a new dataframe.Of course, most people will not go to the shop and buy something every month. But we needan RFM prediction for each individual in every month (between January 1997 and June 1998, 18months in total). When there is no trip in a given month, replace trip, expenditure and quantity tozero. Now, you should be ready to compute recency, frequency and monetary value separately.3 Computing the RFM measures [80%]3.1 Recency [20%] 辅导GBA 464作业、 写作c/c++,Python编程语Keep in mind that for any measure in RFM, we can only use historical data, i.e. data in the monthsbefore the current month. In this note, We define recency as the number of months since the lastmonth with purchase. In the example below, if an individual has been to the store in month 1, 2and 5, her recency is NA in month 1 (because we do not know anything before the data starts), 1 inmonth 2, 1 in month 3, 2 in month 4, 3 in month 5, and 1 in month 6.We talked about an example in class that is similar to this recency measure. However, the waywe constructed that measure Was not optimal. Optionally, try to optimize your algorithm when youconstruct the recency measure.3.2 Frequency [20%]We define frequency as the total number of trips a given individual made in the previous quarter.A quarter is defined as one of Jan-Mar, Apr-Jun, Jul-Sep, Oct-Dec. If the observation is in the very2first of this individual, we assign frequency to NA.3.3 Monetary value [20%]Monetary value is defined as still using Historical data the average monthly expenditure for aconsumer, in the previous months when she purchased something. For example, in month 1, theconsumer came to the store and spent in total 15 dollars. Then, in month 2, her monetary value is15. In month 2, the consumer came again and spent a total of 30 dollars. Then her monetary valuein month 3 is the average, i.e. (15 + 30)/2 = 22.5. She did not come in month 3 and 4, so hermonetary value did not change. Finally, she came in month 5 and spent 20, and thus her monetaryvalue is (15+30+20)/3 = 21.7.3.4 ExampleLets create an artificial example with individual 0. Note that weve already organized the datainto individual-year-month level, and Included the months with no trip. Note that we have computedtrips by counting the number of trips in a Month with purchase. The last row shows that thesestatistics should be re-calculated for the next consumer.id year month trips qty expd quarter recency frequency monval0 1997 1 1 1 15 1 NA NA NA0 1997 2 2 2 30 1 1 NA 150 1997 3 0 0 0 1 1 NA 22.50 1997 4 0 0 0 2 2 3 22.50 1997 5 1 3 20 2 3 3 22.50 1997 6 0 0 0 2 1 3 21.71 1997 1 1 2 29 1 NA NA NAFollowing this example, please calculate recency, frequency and monetary value measures asdefined.34 Targeting [20%]4.1 RFM indexAn RFM index is an weighted sum of the 3 measures, for each individual i in month t:RFMit = b1Rit +b2Fit +b3MitFor now, lets say it is your Marketing teams responsibility to tell you what are the factor loadings.1For now lets take b1 = 0.05, b2 = 3.5 and b3 = 0.05. Note that if a consumer is considered highvalue if she has low recency, or high frequency, or high onetary value. I have coded this sectionalready but you need to run it or change the corresponding variable names.4.2 Validation [20%]When you have computed this measure, sort your sample according to the RFM index and split itinto 10 (roughly) even-sized portions. One way is to use quantile() to generate the cut-offs. Thehigh RFM parts refer to individuals (in particular months) that are more valuable than the low RFMparts of your sample. Examine the average monthly expenditure for each bin of sample, definedby the deciles of the RFM index.2 Plot the average spending (and potentially some other measuresif you want to) by group and confirm that the result is more or less monotonic. Which groups ofconsumers do you want to target?For example, you Might produce something similar to this. You might not get the exact figurebecause the result depends on how you segment the market.1In principle, we Should estimate these loadings and we should use another sample to validate our results.2Deciles: 10% quantiles.4Figure 1: Average expenditure by deciles in the RFM index5如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导