Type : CREATION_INTERNE
Los ejemplos utilizan datos generados internamente a través de bloques DATALINES o tablas CAS temporales.
| 1 | /* Établir une session CAS et créer la bibliothèque 'mycas' */ |
| 2 | cas; |
| 3 | LIBNAME mycas cas; |
| 4 | |
| 5 | /* Création de la table de données d'avis */ |
| 6 | DATA mycas.reviews; |
| 7 | INFILE DATALINES delimiter='|' missover; |
| 8 | LENGTH text $300 category $20; |
| 9 | INPUT text$ positive category$ did; |
| 10 | DATALINES; |
| 11 | This is the greatest phone ever! love it!|1|electronics|1 |
| 12 | The phone's battery life is too short and screen resolution is low.|0|electronics|2 |
| 13 | The screen resolution is low, but I love this tv.|1|electronics|3 |
| 14 | The movie itself is great and I like it, although the resolution is low.|1|movies|4 |
| 15 | The movie's story is boring and the acting is poor.|0|movies|5 |
| 16 | I watched this movie on tv, it's not good on a small screen. |0|movies|6 |
| 17 | watched the movie first and loved it, the book is even better!|1|books |7 |
| 18 | I like the story in this book, they should put it on screen.|1|books|8 |
| 19 | I love the author, but this book is a waste of time, don't buy it.|0|books|9 |
| 20 | ; |
| 21 | RUN; |
| 22 | |
| 23 | /* Prétraitement du texte avec PROC TEXTMINE */ |
| 24 | PROC TEXTMINE DATA=mycas.reviews; |
| 25 | doc_id |
| 26 | did; |
| 27 | var |
| 28 | text; |
| 29 | parse |
| 30 | nonoungroups |
| 31 | notagging |
| 32 | entities = none |
| 33 | outparent = mycas.reviews_bow |
| 34 | outterms = mycas.reviews_terms |
| 35 | reducef = 1; |
| 36 | RUN; |
| 37 | |
| 38 | /* Extraction des règles avec PROC BOOLRULE pour cible binaire 'positive' */ |
| 39 | PROC BOOLRULE |
| 40 | DATA = mycas.reviews_bow |
| 41 | docid = _document_ |
| 42 | termid = _termnum_ |
| 43 | docinfo = mycas.reviews |
| 44 | terminfo = mycas.reviews_terms |
| 45 | minsupports = 1 |
| 46 | mpos = 1 |
| 47 | gpos = 1; |
| 48 | docinfo |
| 49 | id = did |
| 50 | targets = (positive); |
| 51 | terminfo |
| 52 | id = key |
| 53 | label = term; |
| 54 | OUTPUT |
| 55 | ruleterms = mycas.ruleterms_basic |
| 56 | rules = mycas.rules_basic; |
| 57 | RUN; |
| 58 | |
| 59 | /* Affichage des règles générées */ |
| 60 | DATA rules_basic; |
| 61 | SET mycas.rules_basic; |
| 62 | RUN; |
| 63 | |
| 64 | PROC PRINT DATA=rules_basic; |
| 65 | title 'Exemple Basique: Règles pour sentiment positif'; |
| 66 | var target ruleid rule F1 precision recall; |
| 67 | RUN; |
| 68 | |
| 69 | /* Nettoyage */ |
| 70 | PROC CASUTIL; |
| 71 | droptable casdata='reviews' incaslib='mycas'; |
| 72 | droptable casdata='reviews_bow' incaslib='mycas'; |
| 73 | droptable casdata='reviews_terms' incaslib='mycas'; |
| 74 | droptable casdata='ruleterms_basic' incaslib='mycas'; |
| 75 | droptable casdata='rules_basic' incaslib='mycas'; |
| 76 | QUIT; |
| 77 |
| 1 | /* Établir une session CAS et créer la bibliothèque 'mycas' */ |
| 2 | cas; |
| 3 | LIBNAME mycas cas; |
| 4 | |
| 5 | /* Création de la table de données d'avis */ |
| 6 | DATA mycas.reviews; |
| 7 | INFILE DATALINES delimiter='|' missover; |
| 8 | LENGTH text $300 category $20; |
| 9 | INPUT text$ positive category$ did; |
| 10 | DATALINES; |
| 11 | This is the greatest phone ever! love it!|1|electronics|1 |
| 12 | The phone's battery life is too short and screen resolution is low.|0|electronics|2 |
| 13 | The screen resolution is low, but I love this tv.|1|electronics|3 |
| 14 | The movie itself is great and I like it, although the resolution is low.|1|movies|4 |
| 15 | The movie's story is boring and the acting is poor.|0|movies|5 |
| 16 | I watched this movie on tv, it's not good on a small screen. |0|movies|6 |
| 17 | watched the movie first and loved it, the book is even better!|1|books |7 |
| 18 | I like the story in this book, they should put it on screen.|1|books|8 |
| 19 | I love the author, but this book is a waste of time, don't buy it.|0|books|9 |
| 20 | ; |
| 21 | RUN; |
| 22 | |
| 23 | /* Prétraitement du texte avec PROC TEXTMINE */ |
| 24 | PROC TEXTMINE DATA=mycas.reviews; |
| 25 | doc_id |
| 26 | did; |
| 27 | var |
| 28 | text; |
| 29 | parse |
| 30 | nonoungroups |
| 31 | notagging |
| 32 | entities = none |
| 33 | outparent = mycas.reviews_bow |
| 34 | outterms = mycas.reviews_terms |
| 35 | reducef = 1; |
| 36 | RUN; |
| 37 | |
| 38 | /* Extraction des règles avec des options supplémentaires */ |
| 39 | PROC BOOLRULE |
| 40 | DATA = mycas.reviews_bow |
| 41 | docid = _document_ |
| 42 | termid = _termnum_ |
| 43 | docinfo = mycas.reviews |
| 44 | terminfo = mycas.reviews_terms |
| 45 | minsupports = 1 |
| 46 | mpos = 1 |
| 47 | gpos = 1 |
| 48 | nocutoff /* Ne pas couper les règles candidates */ |
| 49 | minrulelen = 1 /* Longueur minimale de la règle */ |
| 50 | maxrulelen = 3 /* Longueur maximale de la règle */ |
| 51 | nthreads = 4; /* Utiliser 4 threads pour le traitement */ |
| 52 | docinfo |
| 53 | id = did |
| 54 | targets = (positive); |
| 55 | terminfo |
| 56 | id = key |
| 57 | label = term; |
| 58 | OUTPUT |
| 59 | ruleterms = mycas.ruleterms_intermediaire |
| 60 | rules = mycas.rules_intermediaire; |
| 61 | RUN; |
| 62 | |
| 63 | /* Affichage des règles générées */ |
| 64 | DATA rules_intermediaire; |
| 65 | SET mycas.rules_intermediaire; |
| 66 | RUN; |
| 67 | |
| 68 | PROC PRINT DATA=rules_intermediaire; |
| 69 | title 'Exemple Intermédiaire: Règles avec options courantes'; |
| 70 | var target ruleid rule F1 precision recall; |
| 71 | RUN; |
| 72 | |
| 73 | /* Nettoyage */ |
| 74 | PROC CASUTIL; |
| 75 | droptable casdata='reviews' incaslib='mycas'; |
| 76 | droptable casdata='reviews_bow' incaslib='mycas'; |
| 77 | droptable casdata='reviews_terms' incaslib='mycas'; |
| 78 | droptable casdata='ruleterms_intermediaire' incaslib='mycas'; |
| 79 | droptable casdata='rules_intermediaire' incaslib='mycas'; |
| 80 | QUIT; |
| 81 |
| 1 | /* Établir une session CAS et créer la bibliothèque 'mycas' */ |
| 2 | cas; |
| 3 | LIBNAME mycas cas; |
| 4 | |
| 5 | /* Création de la table de données d'avis */ |
| 6 | DATA mycas.reviews; |
| 7 | INFILE DATALINES delimiter='|' missover; |
| 8 | LENGTH text $300 category $20; |
| 9 | INPUT text$ positive category$ did; |
| 10 | DATALINES; |
| 11 | This is the greatest phone ever! love it!|1|electronics|1 |
| 12 | The phone's battery life is too short and screen resolution is low.|0|electronics|2 |
| 13 | The screen resolution is low, but I love this tv.|1|electronics|3 |
| 14 | The movie itself is great and I like it, although the resolution is low.|1|movies|4 |
| 15 | The movie's story is boring and the acting is poor.|0|movies|5 |
| 16 | I watched this movie on tv, it's not good on a small screen. |0|movies|6 |
| 17 | watched the movie first and loved it, the book is even better!|1|books |7 |
| 18 | I like the story in this book, they should put it on screen.|1|books|8 |
| 19 | I love the author, but this book is a waste of time, don't buy it.|0|books|9 |
| 20 | ; |
| 21 | RUN; |
| 22 | |
| 23 | /* Filtrage des avis pour une catégorie spécifique (par exemple, 'electronics') */ |
| 24 | DATA mycas.reviews_filtered; |
| 25 | SET mycas.reviews; |
| 26 | where category = 'electronics'; |
| 27 | RUN; |
| 28 | |
| 29 | /* Prétraitement du texte avec PROC TEXTMINE sur les données filtrées */ |
| 30 | PROC TEXTMINE DATA=mycas.reviews_filtered; |
| 31 | doc_id |
| 32 | did; |
| 33 | var |
| 34 | text; |
| 35 | parse |
| 36 | nonoungroups |
| 37 | notagging |
| 38 | entities = none |
| 39 | outparent = mycas.reviews_bow_filtered |
| 40 | outterms = mycas.reviews_terms_filtered |
| 41 | reducef = 1; |
| 42 | RUN; |
| 43 | |
| 44 | /* Extraction des règles avec PROC BOOLRULE sur les données filtrées */ |
| 45 | PROC BOOLRULE |
| 46 | DATA = mycas.reviews_bow_filtered |
| 47 | docid = _document_ |
| 48 | termid = _termnum_ |
| 49 | docinfo = mycas.reviews_filtered |
| 50 | terminfo = mycas.reviews_terms_filtered |
| 51 | minsupports = 1 |
| 52 | mpos = 1 |
| 53 | gpos = 1; |
| 54 | docinfo |
| 55 | id = did |
| 56 | targets = (positive); |
| 57 | terminfo |
| 58 | id = key |
| 59 | label = term; |
| 60 | OUTPUT |
| 61 | ruleterms = mycas.ruleterms_avance |
| 62 | rules = mycas.rules_avance; |
| 63 | RUN; |
| 64 | |
| 65 | /* Affichage des règles générées */ |
| 66 | DATA rules_avance; |
| 67 | SET mycas.rules_avance; |
| 68 | RUN; |
| 69 | |
| 70 | PROC PRINT DATA=rules_avance; |
| 71 | title 'Exemple Avancé: Règles pour les avis électroniques'; |
| 72 | var target ruleid rule F1 precision recall; |
| 73 | RUN; |
| 74 | |
| 75 | /* Nettoyage */ |
| 76 | PROC CASUTIL; |
| 77 | droptable casdata='reviews' incaslib='mycas'; |
| 78 | droptable casdata='reviews_filtered' incaslib='mycas'; |
| 79 | droptable casdata='reviews_bow_filtered' incaslib='mycas'; |
| 80 | droptable casdata='reviews_terms_filtered' incaslib='mycas'; |
| 81 | droptable casdata='ruleterms_avance' incaslib='mycas'; |
| 82 | droptable casdata='rules_avance' incaslib='mycas'; |
| 83 | QUIT; |
| 84 |
| 1 | /* Démarrer une nouvelle session CAS pour un contrôle explicite */ |
| 2 | options casport=5570 cashost='localhost'; |
| 3 | cas my_new_session sessopts=(caslib=casuser timeout=1800 locale="en_US"); |
| 4 | LIBNAME mycas cas; |
| 5 | |
| 6 | /* Création de la table de données d'avis (avec plus de données pour simuler une grande table) */ |
| 7 | DATA mycas.reviews_large; |
| 8 | INFILE DATALINES delimiter='|' missover; |
| 9 | LENGTH text $300 category $20; |
| 10 | INPUT text$ positive category$ did; |
| 11 | DATALINES; |
| 12 | This is the greatest phone ever! love it!|1|electronics|1 |
| 13 | The phone's battery life is too short and screen resolution is low.|0|electronics|2 |
| 14 | The screen resolution is low, but I love this tv.|1|electronics|3 |
| 15 | The movie itself is great and I like it, although the resolution is low.|1|movies|4 |
| 16 | The movie's story is boring and the acting is poor.|0|movies|5 |
| 17 | I watched this movie on tv, it's not good on a small screen. |0|movies|6 |
| 18 | watched the movie first and loved it, the book is even better!|1|books |7 |
| 19 | I like the story in this book, they should put it on screen.|1|books|8 |
| 20 | I love the author, but this book is a waste of time, don't buy it.|0|books|9 |
| 21 | Fantastic product, highly recommend!|1|electronics|10 |
| 22 | Battery drains too fast, very disappointed.|0|electronics|11 |
| 23 | Excellent display and sound quality.|1|electronics|12 |
| 24 | A captivating story, a must-watch!|1|movies|13 |
| 25 | Terrible plot and acting, waste of time.|0|movies|14 |
| 26 | Enjoyed reading every single page.|1|books|15 |
| 27 | Not worth the hype, prefer other titles.|0|books|16 |
| 28 | Best purchase this year!|1|electronics|17 |
| 29 | Worst experience ever, totally unreliable.|0|electronics|18 |
| 30 | Absolutely brilliant, a masterpiece.|1|movies|19 |
| 31 | Couldn't put it down, truly amazing.|1|books|20 |
| 32 | ; |
| 33 | run; |
| 34 | |
| 35 | /* Prétraitement du texte avec PROC TEXTMINE */ |
| 36 | proc textmine data=mycas.reviews_large; |
| 37 | doc_id |
| 38 | did; |
| 39 | var |
| 40 | text; |
| 41 | parse |
| 42 | nonoungroups |
| 43 | notagging |
| 44 | entities = none |
| 45 | outparent = mycas.reviews_bow_large |
| 46 | outterms = mycas.reviews_terms_large |
| 47 | reducef = 1; |
| 48 | run; |
| 49 | |
| 50 | /* Extraction des règles avec PROC BOOLRULE */ |
| 51 | proc boolrule |
| 52 | data = mycas.reviews_bow_large |
| 53 | docid = _document_ |
| 54 | termid = _termnum_ |
| 55 | docinfo = mycas.reviews_large |
| 56 | terminfo = mycas.reviews_terms_large |
| 57 | minsupports = 0.1 /* Support minimum de 10% */ |
| 58 | mpos = 0.5 /* Minimum de positivité de 50% */ |
| 59 | gpos = 0.5 /* Global positivité de 50% */ |
| 60 | maxrulelen = 2 /* Longueur maximale de la règle */ |
| 61 | nthreads = 8; /* Utiliser 8 threads pour le traitement */ |
| 62 | docinfo |
| 63 | id = did |
| 64 | targets = (positive); |
| 65 | terminfo |
| 66 | id = key |
| 67 | label = term; |
| 68 | output |
| 69 | ruleterms = mycas.ruleterms_cas |
| 70 | rules = mycas.rules_cas; |
| 71 | run; |
| 72 | |
| 73 | /* Affichage des règles générées */ |
| 74 | data rules_cas; |
| 75 | set mycas.rules_cas; |
| 76 | run; |
| 77 | |
| 78 | proc print data=rules_cas; |
| 79 | title 'Exemple Viya/CAS: Règles avec gestion de SESSION et performances'; |
| 80 | var target ruleid rule F1 precision recall; |
| 81 | run; |
| 82 | |
| 83 | /* Nettoyage et fin de session CAS */ |
| 84 | proc casutil; |
| 85 | droptable casdata='reviews_large' incaslib='mycas'; |
| 86 | droptable casdata='reviews_bow_large' incaslib='mycas'; |
| 87 | droptable casdata='reviews_terms_large' incaslib='mycas'; |
| 88 | droptable casdata='ruleterms_cas' incaslib='mycas'; |
| 89 | droptable casdata='rules_cas' incaslib='mycas'; |
| 90 | QUIT; |
| 91 | cas my_new_session terminate; |
| 92 |