Categories
Mastering Development

Pandas advanced column creation from another dataframe

I have a dataframe like below: df_detail = car_brand car_type 0 Toyota Sedan 1 Toyota Truck 2 Honda Truck 3 Mazda Sedan 4 Mazda Convertible I want to create a summary dataframe like below: df_summary= ID car_brand count_Sedan count_Truck count_Convertible 0 Toyota 1 1 0 1 Honda 0 1 0 2 Mazda 1 0 1 […]

Categories
Artificial Intelligence (AI) Mastering Development

Multilabel stratified split for images/object detection

I am working on an object detection model and have thought of looking into stratified splits for the dataset. Now since I am doing object detection I have a variable number of "labels" for every image because in each image there is variable number of occurrences for each object I am looking for (car, truck, […]

Categories
Mastering Development

Retrieve content from xml file using xsl 1.0

I have below xml file <?xml version="1.0" encoding="UTF-8"?> <document version="1.0" xmlns="http://www.sdl.com/xpp"> <pages> <page relpgnum="15" pagetype="right"> <stream type="main" sx="0" sy="0" ssx="0" ssy="0" groupnum="1" svjmode="justify" epfilltype="none" class="0" rotate="0" strmrot="0" vj_space="0" cerrors="true"> <block type="main" bx="0" by="22" bsx="312" bsy="509" bisy="509" biy="22" rotate="0" svjmode="justify" btextlen="325.25" bslack="17.5" vjerr="18.75" pgtbl="0" ipcnum="0" ipcgnum="1" trymode="expand" fipcblk="true" lipcblk="true" original="true" bottom="true"> <group class="para.text" pclass="/publication/publication.body/topic/topic.body/analytical.level/analytical.level.body/analytical.level/analytical.level.body/section.block/section/section.body/para" dh="/publication/publication.body/topic/topic.body/analytical.level/analytical.level.body/analytical.level/analytical.level.body/section.block/section/section.body/para/para.text" style="para.text.1"> […]

Categories
Mastering Development

understanding top n tfidf features in TfidfVectorizer

I am trying to understand the TfidfVectorizer of scikit-learn a bit better. The following code has two documents doc1 = The car is driven on the road,doc2 = The truck is driven on the highway. By calling fit_transform a vectorized matrix of tf-idf weights is generated. According to the tf-idf value matrix, shouldn’t highway,truck,car be […]

Categories
Mastering Development

Creating new output from 2 CSVs in Python (data manipulation)

I have a csv file called cities formatted like so: City_id,City,Population,Weather,State la01,LA,24,72,CA ny01,NY,12,42,NY bo01,BO,32,65,BO and another csv called shipping: Carrier,Type,Path,Packages,Max_Packages UPS,Truck,la01-ny01,100,200 UPS,Truck,la01-bo01,100,200 UPS,Air,la01-ny01,100,500 UPS,Air,bo01-ny01,100,500 I need to write these to a string where each row starts with the city and has a list of all its destinations (the list should be sorted by type): la01:LA […]

Categories
Mastering Development

write dictionary of lists to a tab delimited file in python, with dictionary key values as columns

the dictionary I am using is: dict={‘item’: [1,2,3], ‘id’:[‘a’,’b’,’c’], ‘car’:[‘sedan’,’truck’,’moped’], ‘color’: [‘r’,’b’,’g’], ‘speed’: [2,4,10]} I am trying to produce a tab delimited out put as such: item id 1 a 2 b 3 c The code I have written: with open(‘file.txt, ‘w’) as tab_file: dict_writer = DictWriter(tab_file, dict.keys(), delimiter = ‘\t’) dict_writer.writeheader() dict_writer.writerows(dict) specifically, I […]

Categories
Mastering Development

How can I round my float to two decimal places, incorporate the current month and year, and fix my loop?

import java.util.Calendar; import java.text.SimpleDateFormat; import java.util.Scanner; public class carwip { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int sedan, truck, suv, comm1, comm2, comm3; float base_salary=3200.45f; float tax=.08f; char answer; Calendar cal = Calendar.getInstance(); int currentMonth = cal.get(Calendar.MONTH) + 1; int currentYear = cal.get(Calendar.YEAR); System.out.println(“Please enter your name.”); String name=sc.nextLine(); System.out.println(“How many sedans […]

Categories
Development

Extract Value Labels from a Stata file loaded with Haven (Value Labels not Variable Labels)

I am trying to get a list of the value labels from a data.frame I loaded with haven. My variables are stored as haven_labelled and I know that the value labels are there because when I run str() they are listed as an attribute. str( x$tranwork ) ‘haven_labelled’ num [1:498381] NA NA NA NA NA […]

Categories
Artificial Intelligence (AI) Development

Accuracy scores in a Deep Learning project

I’m using three pre-trained deep learning models to detect vehicles and count from an image data set. The vehicles belong to one of these classes [‘car’, ‘truck’, ‘motorcycle’, ‘bus’]. So, for a sample I have manually counted number of vehicles in each image. Also, I employed the three deep learning models and obtained the vehicle […]

Categories
Development

Confused about two dimensional factor in R

I have the following data frame: dat <- data.frame(toys = c(“yoyo”, “doll”, “duckie”, “tractor”, “airplaine”, “ball”, “racecar”, “dog”, “jumprope”, “car”, “elephant”, “bear”, “xylophone”, “tank”, “checkers”, “boat”, “train”, “jacks”, “truck”, “whistle”, “pinwheel”), price = c(1.22, 2.75, 1.85, 5.97, 6.47, 2.16, 7.13, 4.57, 1.46, 5.18, 3.16, 4.89, 7.11, 6.45, 4.77, 8.04, 6.71, 2.31, 6.21, 0.98, 0.87)) I […]