D212_JBT_Task2
.pdf
keyboard_arrow_up
School
Western Governors University *
*We aren’t endorsed by this school
Course
D212
Subject
Computer Science
Date
Jun 21, 2024
Type
Pages
14
Uploaded by MajorMouseMaster1147
In [1]:
import
pandas as
pd
from
pandas.api.types import
CategoricalDtype
import
numpy as
np
import
matplotlib.pyplot as
plt
import
seaborn as
sns
from
sklearn.preprocessing import
StandardScaler
from
sklearn.decomposition import
PCA
from
sklearn.model_selection import
train_test_split
from
sklearn.tree import
DecisionTreeClassifier
from
sklearn.metrics import
confusion_matrix
from
sklearn.metrics import
roc_auc_score
from
sklearn.metrics import
roc_curve
from
sklearn.metrics import
accuracy_score
# import warnings filter
from
warnings import
simplefilter
# ignore all future warnings
simplefilter
(
action
=
'ignore'
, category
=
FutureWarning
)
# The CSV's first column is an index and Pandas will duplicate this and create df =
pd
.
read_csv
(
'./medical_clean.csv'
, index_col
=
0
)
In [2]:
# Check data types and count of values
df
.
info
()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 10000 entries, 1 to 10000
Data columns (total 49 columns):
# Column Non-Null Count Dtype --- ------ -------------- ----- 0 Customer_id 10000 non-null object 1 Interaction 10000 non-null object 2 UID 10000 non-null object 3 City 10000 non-null object 4 State 10000 non-null object 5 County 10000 non-null object 6 Zip 10000 non-null int64 7 Lat 10000 non-null float64
8 Lng 10000 non-null float64
9 Population 10000 non-null int64 10 Area 10000 non-null object 11 TimeZone 10000 non-null object 12 Job 10000 non-null object 13 Children 10000 non-null int64 14 Age 10000 non-null int64 15 Income 10000 non-null float64
16 Marital 10000 non-null object 17 Gender 10000 non-null object 18 ReAdmis 10000 non-null object 19 VitD_levels 10000 non-null float64
20 Doc_visits 10000 non-null int64 21 Full_meals_eaten 10000 non-null int64 22 vitD_supp 10000 non-null int64 23 Soft_drink 10000 non-null object 24 Initial_admin 10000 non-null object 25 HighBlood 10000 non-null object 26 Stroke 10000 non-null object 27 Complication_risk 10000 non-null object 28 Overweight 10000 non-null object 29 Arthritis 10000 non-null object 30 Diabetes 10000 non-null object 31 Hyperlipidemia 10000 non-null object 32 BackPain 10000 non-null object 33 Anxiety 10000 non-null object 34 Allergic_rhinitis 10000 non-null object 35 Reflux_esophagitis 10000 non-null object 36 Asthma 10000 non-null object 37 Services 10000 non-null object 38 Initial_days 10000 non-null float64
39 TotalCharge 10000 non-null float64
40 Additional_charges 10000 non-null float64
41 Item1 10000 non-null int64 42 Item2 10000 non-null int64 43 Item3 10000 non-null int64 44 Item4 10000 non-null int64 45 Item5 10000 non-null int64 46 Item6 10000 non-null int64 47 Item7 10000 non-null int64 48 Item8 10000 non-null int64 dtypes: float64(7), int64(15), object(27)
memory usage: 3.8+ MB
In [3]:
# Data Cleaning Code from D206
# Replace the city-specific values with the standard time zones
df
.
TimeZone
.
replace
(
{
'America/Chicago' : 'America - Central'
,
'America/New_York' : 'America - Eastern'
,
'America/Los_Angeles' : 'America - Pacific'
,
'America/Denver' : 'America - Mountain'
,
'America/Detroit' : 'America - Eastern'
,
'America/Indiana/Indianapolis' : 'America - Eastern'
,
'America/Phoenix' : 'America - Mountain'
,
'America/Boise' : 'America - Mountain'
,
'America/Anchorage' : 'America - Alaskan'
,
'America/Puerto_Rico' : 'America - Atlantic'
,
'Pacific/Honolulu' : 'America - Hawaii-Aleutian'
,
'America/Menominee' : 'America - Central'
,
'America/Nome' : 'America - Alaskan'
,
'America/Indiana/Vincennes' : 'America - Eastern'
,
'America/Sitka' : 'America - Alaskan'
,
'America/Kentucky/Louisville' : 'America - Eastern'
,
'America/Toronto' : 'America - Eastern'
,
'America/Indiana/Tell_City' : 'America - Central'
,
'America/Indiana/Marengo' : 'America - Eastern'
,
'America/North_Dakota/Beulah' : 'America - Central'
,
'America/Indiana/Winamac' : 'America - Eastern'
,
'America/Indiana/Vevay' : 'America - Eastern'
,
'America/North_Dakota/New_Salem' : 'America - Central'
,
'America/Indiana/Knox' : 'America - Eastern'
,
'America/Yakutat' : 'America - Alaskan'
,
'America/Adak' : 'America - Hawaii-Aleutian'
}, inplace
=
True
)
# Convert the column type of zip from int to string then front fill with zeroes
df
[
'Zip'
] =
df
[
'Zip'
]
.
astype
(
"str"
)
.
str
.
zfill
(
5
)
# Convert column that are string object to category
df
[
"TimeZone"
] =
df
[
"TimeZone"
]
.
astype
(
"category"
)
df
[
"Area"
] =
df
[
"Area"
]
.
astype
(
"category"
)
df
[
"Marital"
] =
df
[
"Marital"
]
.
astype
(
"category"
)
df
[
"Gender"
] =
df
[
"Gender"
]
.
astype
(
"category"
)
df
[
"Initial_admin"
] =
df
[
"Initial_admin"
]
.
astype
(
"category"
)
df
[
"Complication_risk"
] =
df
[
"Complication_risk"
]
.
astype
(
"category"
)
df
[
"Services"
] =
df
[
"Services"
]
.
astype
(
"category"
)
# Convert column that are float to integer
df
[
"Initial_days"
] =
df
[
"Initial_days"
]
.
astype
(
"int64"
)
# Recast object to boolean by changing the Yes to 1 and No to 0
bool_mapping =
{
"Yes" : 1
, "No" : 0
}
# Convert column that are string to boolean
df
[
"ReAdmis"
] =
df
[
"ReAdmis"
]
.
map
(
bool_mapping
)
df
[
"Soft_drink"
] =
df
[
"Soft_drink"
]
.
map
(
bool_mapping
)
df
[
"HighBlood"
] =
df
[
"HighBlood"
]
.
map
(
bool_mapping
)
df
[
"Stroke"
] =
df
[
"Stroke"
]
.
map
(
bool_mapping
)
df
[
"Overweight"
] =
df
[
"Overweight"
]
.
map
(
bool_mapping
)
df
[
"Arthritis"
] =
df
[
"Arthritis"
]
.
map
(
bool_mapping
)
df
[
"Diabetes"
] =
df
[
"Diabetes"
]
.
map
(
bool_mapping
)
df
[
"Hyperlipidemia"
] =
df
[
"Hyperlipidemia"
]
.
map
(
bool_mapping
)
df
[
"BackPain"
] =
df
[
"BackPain"
]
.
map
(
bool_mapping
)
df
[
"Anxiety"
] =
df
[
"Anxiety"
]
.
map
(
bool_mapping
)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
write java code implemention (input and output) for B Tree Insertion – with different t values (t=3 or above).
arrow_forward
A new property was added to the search key in order to manage the problem of search keys that were not unique. What kind of an impact may this alteration have on the height of the B+ tree?
arrow_forward
Implement the Binomial Tree Using Java-Generic-Programing, which provide thefollowing menu1. Insert2. Delete3. Search4. Print (The Binomial Tree)5. Quit
arrow_forward
in java
you have to implement some basic methods for BST's (with a little twist). Each nodein the tree has a data element (an integer) and links (possibly null) to its left and right children (youcan also include parent but not compulsory).1. Sample TreeNodeclass TreeNode{int key;TreeNode left;TreeNode right;TreeNode parent; //optional}You have to implement the given functions in Binary search Tree class.2. Binary Search Trees (BST)You are required to implement a Binary Search Tree (BST) ADT (Abstract Data Type). Followingfunctionalities are expected.2.1 ConstructorCreates an empty Binary Search Tree.2.3 Inserts a new node in BST (Standard Insert)Inserts a new node in BST.2.4 DeleteDeletes a node from a BST (Standard Delete)2.5 LookupFind a value in the tree, lookup is a fancy name of find function2.6 SizeReturns the total number of nodes in a BST2.7 MaxDepthReturns the depth of the longest path in a Binary Search Tree.
arrow_forward
A new property was added to the search key to address non-unique search keys. What impact may this modification have on the height of the B+-tree?
arrow_forward
Consider a tree that has a relatively high (between 10 to 30) typical number of children of each node.
Under what conditions would a static child pointer array implementation be usable, and under what conditions would it be a better choice?
Under what conditions would a dynamic child pointer array implementation be usable, and under what conditions would it be a better choice?
arrow_forward
Please implement the followings:
1. Create the binary tree with 9 nodes by using pointer-based representation. struct TreeNode { int info; TreeNode * left; TreeNode * right; }
2. Implement pre-order, in-order, and post-order traversals, and print the results of the tree (Figure 1). 2 7 5 2 6 9 5 11 4
(Figure 1 and question in image below). Please help with number 2. Thank you.
arrow_forward
Write some code to evaluate the efficiency of the Java HuffmanTree class.
a. The software will need to read a text and produce a character frequency table.After the table is built, a Huffman code tree is created, and the file's code becomes a sequence of '0' and '1' characters.
c. Then, using that string as a model, produce and output the contents of the original file.
arrow_forward
Create a UI for general trees (trees with an infinite degree). When the degree of a tree is no higher than 2, make this interface as consistent as feasible with BinaryTrees.
arrow_forward
Procedure. During the course of this project you are to:1. Construct a tree of Hex-a-Pawn board positions. Each node of the tree is called a GameTree. The structure of the class is of your own design, but it is likely to be similar to the BinaryTree implementation.2. Construct three classes of Players that play the game of Hex-a-Pawn. These three classes may interact in pairs to play a series of games.
give code to implement
arrow_forward
Implement the Binary Tree data structure for string data with all of its associated operations.
Apply it for the following applications
1. Store 10 names of cities of Pakistan.
2. Search name of a city in tree.
3. Remove 3 names.
4. Add 2 names of any other cities, besides already used.
5. Search for newly added cities.
Subject: Data Structure Algorithm ( Language C++)
arrow_forward
1. Insert operation on AVL Trees2. Delete operation on AVL TreesQuestion 1: For this lab, use your BST code implemented in the previous lab.In this lab, you haveto create a height-balanced tree class named “AVL”. Inherit the BST class publicly in your new“AVL” class. You can add “height” variable in your existing TNode struct implementation.Implement the following methods for AVL class:a. A default Constructor which calls the default constructor of base class (BST class).b. Override the insert method of base class (BST class) in your AVL class, so that the AVL treeremains height-balanced after insertion of a new node.c. Override the delete method of base class (BST class) in your AVL class, so that the AVL treeremains height-balanced after deletion of a node.d. A function “height” which returns the height of the tree. int height()conste. A function “search” which returns a pointer to the value of the node containing the required keybQuestion 2: Now run the following main program.int…
arrow_forward
Write the code in java pls for AVL Tree. Only insert and preorder display method is needed. Please modify the given code as mentioned above.
arrow_forward
implementing a class for creating and storing Binary Search Trees (BST). Each node of this BST will store the roll number, name and CGPA of a student in JAVA
arrow_forward
When a tree is instantiated from the Java Standard Library to store ordered data, the specific type of tree that is returned can be determined?
arrow_forward
4. Write out the sequential representation for the left tree above (with root A) where /' is
used to mark null links.
5. Write Java code that finds the number of children using the sequential representation
in question 4, Linked Implementations Using Array of Child Pointers implementation,
linked implementation left-child/right-sibling.
6. Give a tradeoff to analyze the data structure and algorithm for the two implementations
used in question 5
arrow_forward
Create an implementation of a binary tree using the recursive approach introduced in the chapter. In this approach, each node is a binary tree. Thus a binary tree contains a reference to the element stored at its root as well as references to its left and right subtrees. You may also want to include a reference to its parent.
arrow_forward
Design and implement a class for B-trees.
arrow_forward
implementing a simple binary search tree capable of storing and retrieving student information. The class should have private member variables (each separated by a tab):
student's id number - an integer
student's name - a string
student's declared major
The class should have private member functions as a minimum:
openFile - opens the input file
testFile - tests the input file has been opened properly
readFile - reads in one student's information
closeFile - close the input file
insert - inserts the students information into the proper place in the tree structure
search - search for the student id entered by the user
inorder - traverses the tree structure
prompt - prompts the user for a student id number
validate - validate the user input value
display - display the contents of the binary tree
results - student id found or not found result
The class should have public member functions
class constructor (if needed)
driver - order of execution
The input file layout:student id…
arrow_forward
Implementing a simple binary search tree capable of storing and retrieving student information. The class should have private member variables (each separated by a tab):
student's id number - an integer
student's name - a string
student's declared major
The class should have private member functions as a minimum:
openFile - opens the input file
testFile - tests the input file has been opened properly
readFile - reads in one student's information
closeFile - close the input file
insert - inserts the students information into the proper place in the tree structure
search - search for the student id entered by the user
inorder - traverses the tree structure
prompt - prompts the user for a student id number
validate - validate the user input value
display - display the contents of the binary tree
results - student id found or not found result
The class should have public member functions
class constructor (if needed)
driver - order of execution
The input file layout:student id…
arrow_forward
Create a binary tree implementation using the recursive technique taught in the chapter. Each node in this method is a binary tree. As a result, a binary tree has a reference to the element stored at its root, as well as pointers to its left and right subtrees.You should also add a reference to its parent.
arrow_forward
Build a tree identification code.
please Fast
thank you
arrow_forward
A binary search tree is a data structure that consists of JavaScript objects called "nodes". A tree always has a root node which holds its own integer value property and can have up to two child nodes (or leaf nodes), a left and right property. A leaf node holds a value attribute and, likewise, a left and right attribute each potentially pointing to another node in the binary tree. Think of it as a javascript object with potentially more sub-objects referenced by the left and right attributes. There are certain rules that apply to a binary tree: A node's left leaf node has a value that is <= than to its own value A node's right leaf node has a value that is => its own value. In other words: let node = { value: left: right: = this object's value> } You will be writing a function called isPresent that takes two arguments: the root object and a value (number), and returns a boolean true if the value is present in the tree or false if it is not present.
function isPresent(root,…
arrow_forward
What would be the appropriate kind of tree traversal to use?
You're writing an analysis tool for a hierarchical organization, in which there is one person fundamentally in charge, to whom some number of people report, to each of whom some number of people report, and so on. There is a ranking in the organization, so the person in charge has rank 1, the people who report to that person have the rank 2, the people who report to the rank-2 people have the rank 3, and so on. Your input is this kind of organizational hierarchy. Your desired output is to be able to find the highest-ranking person (i.e., the person with the minimum rank number) who meets some characteristic (such as the highest-ranking person under 30 years old).
Your input is a binary tree that is an expression tree, in which each non-leaf node contains a binary mathematical operator (such as +, −, ×, or ÷) and each leaf node contains a numeric value (such as 2 or 9.5). Your desired output is the value of the expression…
arrow_forward
You are implementing a binary search tree class from scratch, which, in additionto insert, find, and delete, has a method getRandomNode() which returns a random nodefrom the tree. All nodes should be equally likely to be chosen. Design and implement an algorithm for getRandomNode, and explain how you would implement the rest of the methods.
arrow_forward
During lecture, we talked about an alternate way of implementing trees known as sibling trees.
In a sibling tree, each node stores an item, a link to its first child (if any), and a link to its first sibling (if any).
For example, the abstract tree given on the left would be represented as the structure on the right. Here i means item, s means sibling, and c means child.
i
5
null
i
2
i
4
i
3
2
4
3
null
c null
i
s null
7
6
i
7
i
6
1
null
c null
null
null
The ADT is shown below:
class IntSibTree {
public:
int item;
IntSibTree *sibling; // link to sibling
IntSibIree *child; // link to first child
};
Fill in the preOrder function below that performs a pre-order traversal of an IntSibTree and prints out the items. For the above tree, preOrder should print the items in order: 5247631.
int preOrder (IntSibTree *t) {
if (t == NULL) { return; }
// Copy this function in the answer and add code below this line.
arrow_forward
In Java, import TreeMap
arrow_forward
Write Red–Black Tree Implementation CodeRather than break up the code with explanations show the complete codefor a red–black tree implementation in one piece, with a description of thecode.
arrow_forward
In a short paragraph, explain how the Render Tree will differentiate from the DOM tree, and vice versa. Explain at least 3 differences.
arrow_forward
Develop a program in Java to demonstrate the operations of an B+ -Tree. The menu should contain following items:
1. Insert
2. Delete
3. Search
4. Display
5. Height
6. Total number of nodes
7. Quit
arrow_forward
What kind of tree is generated for ordered data by the Java Standard Library?
arrow_forward
You are implementing a binary search tree class from scratch, which, in additionto insert, find, and delete, has a method getRandomNode() which returns a random node from the tree. All nodes should be equally likely to be chosen. Design and implement an algorithm for getRandomNode, and explain how you would implement the rest of the methods
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- write java code implemention (input and output) for B Tree Insertion – with different t values (t=3 or above).arrow_forwardA new property was added to the search key in order to manage the problem of search keys that were not unique. What kind of an impact may this alteration have on the height of the B+ tree?arrow_forwardImplement the Binomial Tree Using Java-Generic-Programing, which provide thefollowing menu1. Insert2. Delete3. Search4. Print (The Binomial Tree)5. Quitarrow_forward
- in java you have to implement some basic methods for BST's (with a little twist). Each nodein the tree has a data element (an integer) and links (possibly null) to its left and right children (youcan also include parent but not compulsory).1. Sample TreeNodeclass TreeNode{int key;TreeNode left;TreeNode right;TreeNode parent; //optional}You have to implement the given functions in Binary search Tree class.2. Binary Search Trees (BST)You are required to implement a Binary Search Tree (BST) ADT (Abstract Data Type). Followingfunctionalities are expected.2.1 ConstructorCreates an empty Binary Search Tree.2.3 Inserts a new node in BST (Standard Insert)Inserts a new node in BST.2.4 DeleteDeletes a node from a BST (Standard Delete)2.5 LookupFind a value in the tree, lookup is a fancy name of find function2.6 SizeReturns the total number of nodes in a BST2.7 MaxDepthReturns the depth of the longest path in a Binary Search Tree.arrow_forwardA new property was added to the search key to address non-unique search keys. What impact may this modification have on the height of the B+-tree?arrow_forwardConsider a tree that has a relatively high (between 10 to 30) typical number of children of each node. Under what conditions would a static child pointer array implementation be usable, and under what conditions would it be a better choice? Under what conditions would a dynamic child pointer array implementation be usable, and under what conditions would it be a better choice?arrow_forward
- Please implement the followings: 1. Create the binary tree with 9 nodes by using pointer-based representation. struct TreeNode { int info; TreeNode * left; TreeNode * right; } 2. Implement pre-order, in-order, and post-order traversals, and print the results of the tree (Figure 1). 2 7 5 2 6 9 5 11 4 (Figure 1 and question in image below). Please help with number 2. Thank you.arrow_forwardWrite some code to evaluate the efficiency of the Java HuffmanTree class. a. The software will need to read a text and produce a character frequency table.After the table is built, a Huffman code tree is created, and the file's code becomes a sequence of '0' and '1' characters. c. Then, using that string as a model, produce and output the contents of the original file.arrow_forwardCreate a UI for general trees (trees with an infinite degree). When the degree of a tree is no higher than 2, make this interface as consistent as feasible with BinaryTrees.arrow_forward
- Procedure. During the course of this project you are to:1. Construct a tree of Hex-a-Pawn board positions. Each node of the tree is called a GameTree. The structure of the class is of your own design, but it is likely to be similar to the BinaryTree implementation.2. Construct three classes of Players that play the game of Hex-a-Pawn. These three classes may interact in pairs to play a series of games. give code to implementarrow_forwardImplement the Binary Tree data structure for string data with all of its associated operations. Apply it for the following applications 1. Store 10 names of cities of Pakistan. 2. Search name of a city in tree. 3. Remove 3 names. 4. Add 2 names of any other cities, besides already used. 5. Search for newly added cities. Subject: Data Structure Algorithm ( Language C++)arrow_forward1. Insert operation on AVL Trees2. Delete operation on AVL TreesQuestion 1: For this lab, use your BST code implemented in the previous lab.In this lab, you haveto create a height-balanced tree class named “AVL”. Inherit the BST class publicly in your new“AVL” class. You can add “height” variable in your existing TNode struct implementation.Implement the following methods for AVL class:a. A default Constructor which calls the default constructor of base class (BST class).b. Override the insert method of base class (BST class) in your AVL class, so that the AVL treeremains height-balanced after insertion of a new node.c. Override the delete method of base class (BST class) in your AVL class, so that the AVL treeremains height-balanced after deletion of a node.d. A function “height” which returns the height of the tree. int height()conste. A function “search” which returns a pointer to the value of the node containing the required keybQuestion 2: Now run the following main program.int…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education