Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python for customer value Analysis

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to use python for customer value analysis, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

A complete data analysis project consists of the following steps:

1) data acquisition: data acquisition is divided into local text files, database links, crawler technology, etc.

2) data storage: save to this file, database, distributed file system, etc.

3) data preprocessing: according to experience, it accounts for 80% of the workload. You can use the Numpy and Pandas tool libraries

4) Modeling and analysis: at this stage, we should first clarify the data structure and select the model according to the project requirements. The common data mining models are shown below:

The common tool libraries at this stage are divided into the following two:

(1) scikit-learn- is suitable for machine learning algorithm library implemented by Python. Scikit-learn can realize common machine learning algorithms such as data preprocessing, classification, regression, dimensionality reduction, model selection and so on.

(2) Tensorflow- is suitable for projects with deep learning and low data processing requirements.

5) Visual analysis: at present, the mainstream visual chemical industry of Python includes Matplotlib, Seaborn, Pyecharts and so on.

In the whole data analysis process, whether it is data extraction, data preprocessing, data modeling and analysis, or data visualization, Python can well support our data analysis work. With the foundation of getting started with python, we then take "airline customer value analysis as an example" to experience a brief actual analysis process.

Assuming that the data has been collected or recorded before, let's start by importing and preprocessing the data.

1. Handle missing and abnormal values. The code is as follows:

Import numpy as np

Import pandas as pd

Airline_data = pd.read_csv ('.. / data/air_data.csv', encoding='gb18030') # Import aviation data

Print ('shape of raw data is:', airline_data.shape)

# # remove records with empty fares

Exp1 = airline_data ["SUM_YR_1"] .notnull ()

Exp2 = airline_data ["SUM_YR_2"] .notnull ()

Exp = exp1 & exp2

Airline_notnull = airline_data.loc [exp,:]

Print ('the shape of the data after deleting the missing record is:', airline_notnull.shape)

# only keep records where the ticket price is non-zero, or the average discount rate is not 0 and the total mileage is greater than 0.

Index1 = airline_notnull ['SUM_YR_1']! = 0

Index2 = airline_notnull ['SUM_YR_2']! = 0

Index3 = (airline_notnull ['SEG_KM_SUM'] > 0) &\

(airline_notnull ['avg_discount']! = 0)

Airline = airline_notnull [(index1 | index2) & index3]

Print ('the shape of the data after deleting the exception record is:', airline.shape)

2. Select and construct the features of LRFMC model.

# # selecting the characteristics of requirements

Airline_selection = airline [["FFP_DATE", "LOAD_TIME"

"FLIGHT_COUNT", "LAST_TO_END"

"avg_discount", "SEG_KM_SUM"]]

# # Building L feature

L = pd.to_datetime (airline_selection ["LOAD_TIME"]) -\

Pd.to_datetime (airline_selection ["FFP_DATE"])

L = L.astype ("str"). Str.split (). Str [0]

L = L.astype ("int") / 30

# # merging Features

Airline_features = pd.concat ([L, airline_selection.iloc [:, 2:]], axis = 1)

Print ('the top 5 behaviors of the constructed LRFMC feature:\ nFirstline LRFMC features. Head ())

3. The characteristics of standardized LRFMC model.

From sklearn.preprocessing import StandardScaler

Data = StandardScaler () .fit_transform (airline_features)

Np.savez ('.. / data/airline_scale.npz',data)

Print ('the five features of standardized LRFMC are:\ nPersonary data [: 5:])

The above three pieces of code come down to data preprocessing. From this stage, we can see that the most important link is "selecting demand features". Therefore, the premise of analysis is to clarify requirements, and demand research and feature selection are the foundation of all our work. Therefore, we also need to know the domain knowledge or have this area of personnel or domain experts to assist in the analysis work. After standardization, save another copy and do all kinds of tests over and over again to avoid starting all over again.

Use some algorithm to classify customer data, as follows: K-Means clustering analysis code of aviation customer value analysis:

4. Customer value analysis K-Means clustering analysis code

Import numpy as np

Import pandas as pd

From sklearn.cluster import KMeans # Import kmeans algorithm

Airline_scale = np.load ('.. / data/airline_scale.npz') ['arr_0']

K = 5 # # determine the number of clustering centers

# Building a model

Kmeans_model = KMeans (n_clusters = k.jobs.com / jobsbooks 4 / 12 / 12)

Fit_kmeans = kmeans_model.fit (airline_scale) # Model training

Kk=kmeans_model.cluster_centers_ # View Cluster Center

Kmeans_model.labels_ # View the category label of the sample

Kk=kmeans_model.cluster_centers_ # View clustering

Cc_exp = np.savetxt ('.. / data/renwu/cc.txt',kk,fmt= ".18e")

The cc.txt file is as follows:

[0.05184321-0.22680493-0.00266815 2.19136467-0.23125594]

[- 0.31368082-0.57402062 1.68627205-0.1733275-0.53682451]

[0.48333235 2.48322162-0.7993897 0.30863251 2.42474345]

[- 0.7002121-0.16114387-0.41489162-0.25513359-0.16095881]

[1.16067608-0.08691922-0.37722423-0.15590586-0.09484481]

# count the number of samples in different categories

R1 = pd.Series (kmeans_model.labels_) .value_counts ()

Print ('the final number of each category is:\ nnumber of categories R1)

3 24659

4 15740

1 12125

2 5336

0 4184

After analyzing the above data combined with feature attributes and domain knowledge, the clustering results are as follows. Where L represents the time of membership, R represents the length of time from the most recent flight, F represents the number of flights, M represents the total flight history, and C represents the average discount coefficient.

As can be seen from the above cases, in a data analysis case, the workload or time of data collection and preprocessing is about 70% and 80% of the time. After the data is ready, the focus is on the model and training stage, which requires a small amount of code but needs to know what algorithm is suitable for what scenario, and choose statistical algorithms or machine learning algorithms, which is also the stage of data analysis in the postgraduate entrance examination. Choosing the right algorithm to mine the value is of great help. In the last stage, the comprehensive application and analysis of domain knowledge, of course, the mastery of domain knowledge or the participation of domain experts runs through the whole analysis process.

In the process of learning data mining, we also realize that there are many algorithms, and it takes a long time to learn specially. According to personal experience, if the student is no longer the stage, the correct learning method may be to identify the needs first, then determine the appropriate algorithm according to the use of the algorithm, and then only focus on the in-depth study and application of the algorithm.

After reading the above, do you have any further understanding of how to use python for customer value analysis? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report