Scénario de test & Cas d'usage
Entraînement de réseaux de neurones artificiels classiques.
Découvrir toutes les actions de neuralNetCréation d'une table de clients avec des informations sur leur ancienneté, leur forfait actuel, leur consommation de données et s'ils ont souscrit à l'offre (cible). La table est ensuite partitionnée pour l'entraînement et la validation.
| 1 | DATA clients_data; |
| 2 | call streaminit(42); |
| 3 | DO client_id = 1 to 5000; |
| 4 | anciennete_mois = floor(rand('UNIFORM') * 60) + 6; |
| 5 | consommation_go = 5 + rand('NORMAL', anciennete_mois / 2, 10); |
| 6 | IF consommation_go < 0 THEN consommation_go = 5; |
| 7 | revenu_annuel_k = 25 + rand('NORMAL', 40, 15); |
| 8 | IF revenu_annuel_k < 15 THEN revenu_annuel_k = 15; |
| 9 | score_satisfaction = rand('UNIFORM') * 5; |
| 10 | /* La probabilité de souscrire augmente avec la consommation et la satisfaction */ |
| 11 | IF (consommation_go > 40 and score_satisfaction > 3.5 and rand('UNIFORM') > 0.4) THEN a_souscrit = 1; |
| 12 | ELSE a_souscrit = 0; |
| 13 | OUTPUT; |
| 14 | END; |
| 15 | RUN; |
| 16 | |
| 17 | PROC CASUTIL; |
| 18 | load DATA=clients_data outcaslib=casuser casout='CLIENTS_MARKETING' replace; |
| 19 | QUIT; |
| 1 | PROC CAS; |
| 2 | partition.partition TABLE={name='CLIENTS_MARKETING'} |
| 3 | partition={fraction={train=0.75, valid=0.25}, seed=123} |
| 4 | casout={name='CLIENTS_PARTITIONED', replace=true}; |
| 5 | QUIT; |
| 1 | PROC CAS; |
| 2 | ACTION neuralNet.annTrain / |
| 3 | TABLE={name='CLIENTS_PARTITIONED', where='_PartInd_=1'}, |
| 4 | validTable={name='CLIENTS_PARTITIONED', where='_PartInd_=2'}, |
| 5 | inputs={{name='anciennete_mois'}, {name='consommation_go'}, {name='revenu_annuel_k'}, {name='score_satisfaction'}}, |
| 6 | target='a_souscrit', |
| 7 | nominals={{name='a_souscrit'}}, |
| 8 | hiddens={20, 10}, |
| 9 | arch='MLP', |
| 10 | std='STD', |
| 11 | errorFunc='ENTROPY', |
| 12 | nloOpts={ |
| 13 | algorithm='LBFGS', |
| 14 | validate={stagnation=4} |
| 15 | }, |
| 16 | casOut={name='marketing_model_weights', replace=true}, |
| 17 | saveState={name='marketing_model_state', replace=true}; |
| 18 | QUIT; |
L'action s'exécute avec succès et produit un modèle de classification. Les tables de poids ('marketing_model_weights') et d'état ('marketing_model_state') sont créées dans CAS. Le journal des itérations montre que l'entraînement s'est arrêté en raison de la stagnation de l'erreur sur le jeu de validation, prouvant que le mécanisme d'arrêt précoce a fonctionné comme prévu.