+1 (208) 254-6996 [email protected]
  

This is easy python lab. You can read the Programming assignment.pdf and do the lab.  

The files that i attached are need for the lab. This is very very quick and easy lab for python

Don't use plagiarized sources. Get Your Custom Essay on
Python:: Easy Lab
Just from $13/Page
Order Essay

# cse5120_great_pizza.py # for “CSE 5120 in March with Dr. Voigt” # cut and paste into cse512_decrule_learn.py DATATABLE = \ [{‘id’ : 1, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 2, ‘red’ : 1, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 1},\ {‘id’ : 3, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 4, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 5, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 6, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 7, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 8, ‘red’ : 0, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 9, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 10, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 11, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 12, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 13, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 14, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 15, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 1},\ {‘id’ : 16, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 17, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 18, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 19, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 20, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 21, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 22, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 23, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 1},\ {‘id’ : 24, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 25, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 26, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 27, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 28, ‘red’ : 1, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 1},\ {‘id’ : 29, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 30, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 31, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 32, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 33, ‘red’ : 1, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 34, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 35, ‘red’ : 0, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 36, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 1, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 37, ‘red’ : 0, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 38, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 39, ‘red’ : 0, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 1},\ {‘id’ : 40, ‘red’ : 0, ‘meat’ : 1, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0},\ {‘id’ : 41, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 0, ‘anchov’ : 0, ‘crust’ : 1, ‘ok’ : 0},\ {‘id’ : 42, ‘red’ : 0, ‘meat’ : 0, ‘seaf’ : 1, ‘anchov’ : 0, ‘crust’ : 0, ‘ok’ : 0}] ATTRIBS = [‘red’, ‘meat’, ‘seaf’, ‘anchov’, ‘crust’] DEC = ‘ok’

 cse5120_decrule_learn.py # CSE 5120 in March with Dr. Voigt # after Nils Nilsson’s GSCA algorithm # Student Programmer Name _________________________ # Student ID ____________________________ import random # the example from Nils Nilsson textbook DATATABLE = [{‘id’:1, ‘app’:1, ‘rat’: 0, ‘inc’: 0, ‘bal’:1, ‘ok’: 0},\ {‘id’:2, ‘app’:0, ‘rat’: 0, ‘inc’: 1, ‘bal’:0, ‘ok’: 0},\ {‘id’:3, ‘app’:1, ‘rat’: 1, ‘inc’: 0, ‘bal’:1, ‘ok’: 1},\ {‘id’:4, ‘app’:0, ‘rat’: 1, ‘inc’: 1, ‘bal’:1, ‘ok’: 1},\ {‘id’:5, ‘app’:0, ‘rat’: 1, ‘inc’: 1, ‘bal’:0, ‘ok’: 0},\ {‘id’:6, ‘app’:1, ‘rat’: 1, ‘inc’: 1, ‘bal’:0, ‘ok’: 1},\ {‘id’:7, ‘app’:1, ‘rat’: 1, ‘inc’: 1, ‘bal’:1, ‘ok’: 1},\ {‘id’:8, ‘app’:1, ‘rat’: 0, ‘inc’: 1, ‘bal’:0, ‘ok’: 0},\ {‘id’:9, ‘app’:1, ‘rat’: 1, ‘inc’: 0, ‘bal’:0, ‘ok’: 0}] ATTRIBS = [‘app’, ‘rat’, ‘inc’, ‘bal’] DEC = ‘ok’ # continue with your program starting here …

CSE 5120 in March of 2021 wit Dr. Voigt

Programming Assignment

Total Points: 25

This is a programming assignment that is aligned with the lecture Modules 6.1 and 6.2 on Inductive Rule Learning.

In particular, this assignment wants you to complete the Inductive Rule Learning program in the Module 6.2 video. The driving function ‘learn_rules()’ and several functions it calls are already provided. You will see calls to other functions without their implementations shown in the Module 6.2 video. To find these, consult the annotation is the Module 6.2 slides that are given along with the video. A bit more code is given in the annotations with just few functions left for you to implement on your own. You will see which …

STEP 1: The top-level function ‘learn_rules()’ assumes that a learning problem has been provided in the form of 3 global variables (every once in a while – here for the sake of convenience to us, the programmers – using globals is fine …). The globals variables that the program assumes are already provided with their initializations: DATATABLE (the set of training instances), ATTRIBS (the list of attributes that describe the concept to be learned), and DEC (the attribute that indicates the binary classification associated with each training instance.). In order to save some typing, you may download file

cse5120_decrule_learn.py

with the globals for the lecture training set. Continue your program by adding on to this file.

STEP 2: Start programming based on the code provided in the video and on the slides. Whenever you come across one of those functions that are to you to program on your own, step back, make sure that you understand the functions purpose, decide on how to accomplish it (none of it is very complicated), then code.

Make the last lines of your program the following:

STEP 3: Attempt to run your program, debug as needed. Your program should reproduce the rule learning outcomes you have seen in the video.

STEP 4: Rerun your program for another set of training instances. In order to have your program load another set of training instances, simply comment out the block of the original DATATABLE, ATTRIBS and DEC lines and in their place cut-and-paste the content of file

cse5120_great_pizza.py

You will find out, on the basis of 42 instances of rated pizzas (choices: red/non-red sauce, meat/no-meat, seafood/no-seafood/, extra-crust/no-extra-crust, ‘anchovies/no-anchovies’), which pizzas are the best 

Python 2 to Python 3: It turns out that part of this assignment will be your converting the lecture code, which is written in Python 2, to Python 3 (which, to my knowledge, Dr. Khan has you use). The conversion is not difficult and just a few statement will need your attention:

1. Convert Python 2 print statements into Python 3 statements; since you have no doubt already been using Python 3 print statements, just by looking at the Python 2 code, you may already know what to do. If not, there are many online sites on this that you can Google. If this becomes a “huge” problem, ask by email either me, our student assistant Benjamin Alexander for pointers.

2. Python 2 ‘raw_input’ becomes Python 3 ‘input’. 3. The Python 2 ‘map’ statement is no longer supported in the same manner by Python 3;

but you can still use it by wrapping a list(…) around the entire ‘map(…)’

CREDIT FOR THIS ASSIGNMENT: Submit via Blackboard Submission Portal under the “CSE 5120 in March’ content area (1) your file decrule_learn.py; make sure that add your name and student id to the top of the file; (2) A screenshot of your running program and output from STEP 3; the screenshot need only show the bottom portion of the output which shows the learned rules, (3) a screenshot showing the rules that your program learned for the run in STEP 4.

Submit partially programs (even those that may not work) for partial credit.

The assignment is due on Tuesday, 3/16, at 11:59pm.

Python tidbits for CSE 5120 March Programming Assignment

Kerstin Voigt, March 2021

Work in Python Shell to test out code snippets

Program loaded

dtab a copy of list DATATABLE

DATATABLE is a list of Python dictionaries

Each line a dictionary that lists KEY : VALUE pairs

Let’s all each line an INSTANCEK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlight

The third instance of datatable dtab

Iterating over all ATTRIBUTES of the instance, Here: just to print

Iterating over all VALUES of the instance, Here: just to print

Iterating over all ITEMS (key:val) of the instance …K. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlight

A Python dictionary is equivalent to a C++ Map data structure;

Use [ ] operator on key to obtain value associated with key

A RULE is represented by plain LIST of attributes; all attribs are are to have value 1 in an instance in order for rule to “cover” the instance (= rule is applicable to instance)

This function definition should go into your .py file …. But for quick prototyping, you CAN define a quick fct within the Pyton shell … benefit of interpreter!K. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlightK. VoigtHighlight

Again: put fct def into .py file; in defined in shell just for demo

DEC is global; here DEC = ‘ok’

Neither of these 4 rules covers any neg instance, i.e., inst wit ‘ok’ : 0

These 2 rules cover one or more neg instances

… find them in listing here …

Empty rule [ ] covers all instances be default; thus TrueK. VoigtHighlightK. VoigtHighlightK. VoigtHighlight

Left to define …

def num_covers(dtab, rule):

… your code …

• Identifies and counts all instances in dtab that are covered by the rule

• Special case: if rule is empty, return the length of dtab bec “all” instances are coverd by rule [ ]

def num_covers_pos(dtab, rule):

… your code …

• Identifies and counts all POSITIVE instances (those with ‘ok’:1) that are covered by the rule

• Special case: if rule is empty, return the number of all positive instances in dtab; they are all covered by rule [ ]K. VoigtHighlightK. VoigtHighlightK. VoigtHighlight

  • Python tidbits for CSE 5120 March Programming Assignment�
  • Slide Number 2
  • Slide Number 3
  • Slide Number 4
  • Slide Number 5
  • Left to define …

CSE 5120 March Programming Assignment “The printing parts”

Kerstin Voigt, March 2021

In the Python interpreter shell:

Type an variable + enter: the interpreter will display the value of this variable

… this can look messy for values that are large data structures

Using Python 3 print to print out the value does not produce any better looking output

messy!

still messy…

Plain Python print(…) is fine for simple values or simple, moderately sized data structures

It you want a data structure to be printed more “neatly aligned”, e.g., in some pseudo tabular form, WE WRITE OUR OWN FUNCTIONS

Note: the only reason that print_table has a second parameter ‘_’, is because my original print_table was a bit more elaborate and took two arguments; to blend with the existing code, the above print_table has been given a “dummy” second argument; by making it ‘_’, it is anonymous, just a placeholder.

To clean things up, remove ‘_’ and remove second argument from print_table calls in the rule learner code … if you want …

def report_rules(rules): …

def report_covers_neg(dtab,rule): … see 6.2 annotated slides …

Plain Python 3 print of a simple string.

Python 3 “formatted” print; printing of a string with parameters; simplest pattern: the ith {} appearing in the string will be replaced with the ith parameter in .format(…).

Numerous formatting option exist, to be set within {} . See tutorials for details.

Sample Output Behavior of the Rule Learner (1st slide of Module 6.1)

Following instructions, your program output should look similar to this:

  • CSE 5120 March Programming Assignment�“The printing parts”�
  • Slide Number 2
  • Slide Number 3
  • Slide Number 4
  • Sample Output Behavior of the Rule Learner�(1st slide of Module 6.1)

Order your essay today and save 10% with the discount code ESSAYHELP