kaitumisuuringute-keskus / weightipy Goto Github PK
View Code? Open in Web Editor NEWRIM iterative raking algorithm for people data
License: MIT License
RIM iterative raking algorithm for people data
License: MIT License
I'm trying to weight a datset using the following code:
import weightipy as wp
gender_targets = {'Q2':{1:49, 2:51}}
region_targets = {'Q4':{1:32, 2:23, 3:10, 4:14, 5:21}}
scheme = wp.Rim('gender_and_age')
scheme.set_targets(targets=[gender_targets, region_targets])
df["respid"] = range(len(df))
engine = wp.WeightEngine(data=df)
engine.add_scheme(scheme=scheme, key="respid", verbose=False)
engine.run()
df_weighted = engine.dataframe()
col_weights = f"weights_{scheme.name}"
respid, Q2, Q3 and Q4 are integer columns.
I get a long error message beginning with:
FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas.
Further down after a series of floating point numbers the error states:
has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
Hi, I used Weightipy to cpmpute my data's weight,the code in below:
`age_targets = {'agecat':{1: 0.067468889, 2: 0.080224503, 3: 0.081368672, 4: 0.084373472, 5: 0.102660891
,6:0.094806186,7:0.090030135,8:0.090639452,9:0.088830485,10:0.077339418,11:0.136466392,98:0.005791506}}
gender_targets = {'gender':{1: 0.488588237, 2: 0.511411763}}
county_targets = {"county":{2:0.019395905,4:0.023782735,5:0.02292341,7:0.02292341,8:0.02088535,9:0.028729086,10:0.021700082
,13:0.034964756,14:0.009158398,15:0.013730506,16:0.004724007,17:0.015997925,18:0.018345312,20:0.011139324
,63:0.107256094,64:0.11836086,65:0.173914542,66:0.118862683,67:0.080211099,68:0.095929136,72:0.006447622}}
scheme = wp.Rim('gender_and_age_and_county')
scheme.set_targets(targets=[age_targets, gender_targets,county_targets])
pres_df["identity"] = range(len(pres_df))
engine = wp.WeightEngine(data=pres_df)
engine.add_scheme(scheme=scheme, key="identity", verbose=False)
engine.run()
df_weighted = engine.dataframe()
col_weights = f"weights_{scheme.name}"
efficiency = wp.weighting_efficiency(df_weighted[col_weights])
`
when run this code,show KeyError: "['gender', 'agecat', 'county'] not in index",how do I to fix it? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.